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!

Getting VBScript to read Windows regional settings for date

Status
Not open for further replies.

Zycmi

IS-IT--Management
Jun 19, 2002
42
0
0
CA
Hi, I was just wondering if there is a way to get my vbscript to search my windows system for the regional settings for date.

I have a date picker running on my machine, and it works wonderfully when the "/" character is used as the delimiter. however, some machines have a "-" character instead. on those machines, it does not work.
Can anyone help.

Thanks in advance.

Zycmi
 
Session.LCID will give you the locale code Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
the LCID only reads the locale code, which is independant from the Date Seperator which may be set differently for some machines...

I have also tried setting the date seperator to "-", then did a response.write date().

it returned the date with "/" as a date seperator. any ideas why this would be?
 
You can make the vbs pull it apart and reassemble however you'd like...


Date1 = cDate("2/3/03")
Date2 = cDate("5-6-2003")

monNum1 = datePart("m",Date1)
monNum2 = datePart("m",Date2)

DayNum1 = datePart("d", Date1)
DayNum2 = datePart("d", Date2)

yearNum1 = datePart("yyyy",Date1)
yearNum2 = datePart("yyyy",Date2)

date1String = monNum1 & "-" & dayNum1 & "-" & yearNum1
date2String = monNum2 & "/" & dayNum2 & "/" & yearNum2
Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048
Tek-Tips Best Practices: FAQ183-3179
 
I've tried your suggestion, however using the DatePart function, I've noticed that the DAY and MONTH values are sometimes switching from one-another.

as in, my date picker sends a date format dependant on the user's machine, which sometimes means it is formatted dd/mm/yyyy, and other times, yyyy/mm/dd. In the case of dd/mm/yyyy, it switches the months and days.

what code would I need to grab each section Correctly every single time, no matter how the date gets sent?

 
If your date picker sends a date format dependant on the user's machine, its not the DatePart function which switches the months and days, it's the date picker.

Presumably your date picker produces a string which is converted into a date, this is where a problem occurs. It might be better to have you date picker produce a long date format like 1-Jan-2003, then convert it to a date. This will ensure the DatePart function will always get the correct part of the date. BDC.
 
I am not sure what problems you are encountering but the DatePicker must be using the Date subtype as its value which means that no matter what the date "looks like" to the user, the date can be handled in the code correctly. There are a number of functions that can be used to manipulate dates that should cover what you need.

With regards to the delimiter problems, if you are using dates as strings you can use the Replace function to convert any unwanted "-" charaters into "/" charaters.
e.g. strDate = Replace(strDate, "-", "/")

Hope this helps

Si [afro]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top