Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Losing Zeros in Date Conversion

Status
Not open for further replies.

Bonediggler1

Technical User
Jul 2, 2008
156
US
Hi-

I am using CDate in conjunction with the format property to turn a string ("07/01/2008") into a date and then subtract one day (i.e. the result should be "06/30/2008"). However, when doing this the zero associated with June ("06") is deleted, even when specifying the "mm/dd/yyyy" format. The relevant code is below:


Dim strFileDate As String
Dim strFileDateA As Date

strFileDateA = Format((CDate(strFileDate) - 1), "mm/dd/yyyy")


Where strFileDate = "07/01/2008". The result is "6/30/2008".


Thank you!!
 
You have defined strFileDateA as a date, so you will get what every you have set-up in international settings (control panel) for your date. Define it as a string if you want to keep the format.
 
You got it!

I changed the short-date format to "mm/dd/yyyy" and it seems to be working now.

Thank you!
 
If you have changed the shortdate format, there is no need to include format in your code.
 
You only need this:
strFileDateA = strFileDate - 1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV-

I don't think that will work as strFileDate is a string, not a date - hence all the formatting code...or am I missing something??

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top