Date Conversion

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello:

If I use CStr(Month(Date)) it returns month as 1 for janurary, 2 for
feburary, etc.

I need to build a string that would include 01 for January and 02 for
February, and 12 for December so the date would be eg. at the end 20050127.

Do I need to use some format conversions? I would appreciate your
assistance.
 
How about
Format(Date(), "yyyymmdd")
?

Hello:

If I use CStr(Month(Date)) it returns month as 1 for janurary, 2 for
feburary, etc.

I need to build a string that would include 01 for January and 02 for
February, and 12 for December so the date would be eg. at the end 20050127.

Do I need to use some format conversions? I would appreciate your
assistance.
 
Hello:

Thanks for your response. I figured out after I had posted that I can use
format but when I was building my string as was using CStr it was not giving
me day and month as one digit. As longs as I did conversion before
converting it to sting and using variables it works ok. So, I am happy.

cday = Format(dtDate, "dd")
cmonth = Format(dtDate, "mm")

and then

todayfilename = CStr(Year(dtDate)) & cmonth & cday & "000.tab"

Thanks again
 
Or, more simply,

todayfilename = Format(DateSerial(Year(dtDate), Month(dtDate), Day(dtDate)),
"yyyymmdd") & "000.tab"
 
Hello:

Thanks Doug - this works well and it is certainly more efficient/elegant code.

Thanks again.
 
Heck, I just realize I'd misread your original equation (and mistyped my
answer anyhow!)

I thought you wanted to use the current year with the month and day from
your variable. That would have been

todayfilename = Format(DateSerial(Year(Date), Month(dtDate), Day(dtDate)),
"yyyymmdd") & "000.tab"

However, since you're wanting everything from dtDate, all you need is

todayfilename = Format(dtDate), "yyyymmdd") & "000.tab"

(which is what John Nurick suggested a few hours before me!)
 
Back
Top