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

Does CDate convert to a date format based on your regional settings?

Status
Not open for further replies.

JennyPeters

Programmer
Oct 29, 2001
228
0
0
US
Does CDate convert to a date format based on the format of your regional settings?

I'm trying to avoid the regional settings as different computers seem to be set up differently...


Thanks,


Jenny
 
No CDate converts the the date system used by VB which in reality is not really a date but, a numeric value representative of the date. However if you are using the Date() or Now() function in concert with the CDate the Date() or Now() functions will use the current system date of the PC or Server. In order to format the Date the way you want it when it has been converted to a date using the CDate() function you must then use the Format() function. With this function you can format the date anyway you wish.

I hope this makes sense.
 
Interrrrrrrrestinnnnnnnng, Verrrrrrrrry, Interrrrrrrrestinnnnnnnng.

Re the following, it (the infamous "CDate" picks and chooses amongst the more "interesting posibilities available?

But then a quick peek at "help" and / or playing w/ the immediate window would reveal all of this (and possibly more?)


? Format(CDate(#4/2/02#), "Long Date")
Tuesday, April 02, 2002

? Format(CDate(#22/11/02#), "Long Date")
Wednesday, November 02, 2022

? Format(CDate(#14/1/02#), "Long Date")
Thursday, January 02, 2014



MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Were you changing the regional settings of your system inbetween each ? statement Michael?

Why the change in outputs?

Jenny
 
You have problem with the sql string?
I meen "MyDate=#" & txtDate & "#"
If You use Access and the separator it's not "/" You will receive an error.
The separator CAN'T be formated by code!
Bu You can transform it!!!

Use this:

Public Function TransformDate(Optional ByVal strDate As String = "") As String
Dim pos As Integer
pos = InStr(1, strDate, ".", vbBinaryCompare)
While pos > 0
strDate = Mid(strDate, 1, pos - 1) & "/" & Mid(strDate, pos + 1)
pos = InStr(1, strDate, ".", vbBinaryCompare)
Wend
TransformDate = strDate
End Function

Your query line will be
"MyDate=#" & transformdate(txtDate) & "#"

 
Jenny,

No change to ANY settings between 'statements'. The changing out put is the indication that Ms. VB is looking at the split (subdivided) input to see wheather the parts are appropiate to a 'regional setting' or generally recognized format. It is -in efffect- asking if the first element can be a 'month' (<= 12) and the second a 'day' (<= Number of days in the month). If 'it' concludes these are not viable entrants, it attempts to select an alternate 'format' - in my examples it selected 'yy/mm'dd' as the al;ternate format. Note that it is possible for a significant range of dates to be 'mis-interperted' with this process.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Further, it is usually necessary to convert dates to their 'stndard' (e.g. U.S.) format for use in queries and many (most? all?) date orientated functions.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top