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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange date formatting problem

Status
Not open for further replies.

laradegroot

Programmer
Joined
Feb 5, 2003
Messages
8
Location
NL
In my application I am retrieving dates from an SQL database in the following format:
Feb 5 2003 12:00PM
Jan 28 2003 12:00PM
Mar 7 2003 12:00PM

I'm using the following code to convert this date to an "understandable" format:
Format(Date, "dd-mm-yy HH:MM")
This works perfectly for all dates ... except those with the month "Mar" or "May". In these cases the date is not converted at all.
Does anyone have any experience with this, or suggestions how to solve this problem??
Thanx! Regards,

Lara
 
hi lara,

it works on mine. i did :

Dim myDate As Date

myDate = CDate("May 31 2003 12:00PM")
Debug.Print Format(myDate, "dd-mm-yy HH:MM")

myDate = CDate("May 28 2003 12:00PM")
Debug.Print Format(myDate, "dd-mm-yy HH:MM")

myDate = CDate("Mar 7 2003 12:00PM")
Debug.Print Format(myDate, "dd-mm-yy HH:MM")

and the output was :
31-05-03 12:00
28-05-03 12:00
07-03-03 12:00

how are you setting the date variable ?


 
The date is retrieved in the format "May 31 2003 12:00PM" by an SQL-query.
The strange thing is that when I try the code you wrote (in an empty project), and that works for you .... it still doesn't work for me (for March and May, it still does work for the other months....)
It doesn't even run the CDate function, but just tells me there's a type mismatch.
 
hi,

ok look at your Date / locale settings in control panel.

I changed mine from English to French.

Then i did

myDate = CDate("May 31 2003 12:00PM")

and i get type mismatch. This is, i assume, because in French May is not a valid month name, its mars ...

thus,

myDate = CDate("mars 31 2003 12:00PM")
Debug.Print Format(myDate, "dd-mm-yy HH:MM")

works.


are you the same lara that did tomb raider ? :¬)
 
Okay, I found the problem. Somehow my regional settings (US) were not affecting VB. Therefor it did not recognize that "Mar" was the month of March.
Problem solved, thanx a lot for your help!!
Regards,

Lara :-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top