Formatting variable of type date to be used in a string

krice1974

Active Member
Joined
Jul 3, 2008
Messages
422
Hi all. I'm trying to increment a variable NextDay (of type date) +1 every time through a loop. With each pass, the NextDay variable gets passed to a string, to be the address of a web query. So. I need to change the format I'm getting (3/19/09) to ("yyyymmdd") but I'm not sure of the syntax. Thanks in advance.


Code:
Dim NextDay As Date         'The variable that holds the date being checked
Dim NextDayString As String 'The web address that holds the variable to change the date. Passed to the query in the loop.
Dim EA As Worksheet         'Earnings worksheet
Dim i As Integer            'loop counter
 
For i = 1 To 30     'Loop counter, get each date and data with each pass.
    'Format desired (needed for string address is Format("yyyymmdd")
    NextDay = Date + i
    'Yahoo address: [URL]http://biz.yahoo.com/research/earncal/20090320.html[/URL] (includes date of March 20, 2009)
    NextDayString = "[URL]http://biz.yahoo.com/research/earncal/[/URL]" & NextDay & ".html"
    MsgBox NextDayString
Next i
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,213,521
Messages
6,114,109
Members
448,548
Latest member
harryls

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top