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

Formatting Dates

Status
Not open for further replies.

AgentM

MIS
Jun 6, 2001
387
US
Hi,

Is there a way I can retrieve the format of date or Time depending on the current locale?

Currently, I am setting a variable sdate using sdate=FormateDate(Now(),"mm/dd/yyyy")
This sdate it used to run commandline tasks.
The format "mm/dd/yyyy" works fine for en-us locale but will not work for other locales.

So is there an algorithm that I can use to get the format "mm/dd/yyyy".

Cannot use setlocale and getlocale.

Any ideas appereciated.

Thank you
 
FormatDateTime(Now(),vbShortDate)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
And if the constant is not defined:
FormatDateTime(Now(), 2)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thankx PHV,
But I don't need the date, I need the format the date is in whether ie. "mm/dd/yyyy" or dd.mm.yyyy
or yyyy/dd/mmm


Any ideas let me know.
Thank you.

 
So you have a date and you just want to know what format it is in?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Yes, is there a function that does it or will I need to write one.
 
To get the local format:
tstDate=#2005-12-31#
strFormat=Replace(Replace(Replace(Replace(FormatDateTime(tstDate,2),"2005","yyyy"),"05","yy"),"12","mm"),"31","dd")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That will work if the date doesn't change and the date separators don't change and if the month and date are not same.

Thankx, you have put me in the right direction.
 
That will work if the date doesn't change
My code use a fixed non ambiguous date to discover the current locale setting, dot.
It is in no way able to decipher the format of an unknown date.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top