Dr
Fri Dec 30 16:39:25 CST 2005
JRS: In article <OhocBBPDGHA.984@tk2msftngp13.phx.gbl>, dated Fri, 30
Dec 2005 14:22:22 local, seen in news:microsoft.public.scripting.vbscrip
t, dc <dannyc@accoalde.com.au> posted :
>I am using the regional date time settings as English(Australian). That
>means that my date settings will always display as day/month/year
>
>I have an app which I'm entering a date. It's written in VB.
>When I intercept my field after its been entered and use VBScript to display
>a msgbox to screen I get funny results which seem to be a VB Script bug.
>
>I enter
>11/01/2006 (which means in my lingo 11th Jan 2006)
>
>I then display
>msgbox DAY(myfield) & MONTHNAME(Month(myfield)) & YEAR(myfield) and lo I get
>"1Nov2006".
>
>I can also use
>MSGBOX FormatDateTime(myfield,1) and get Wednesday, 1 November 2006
>
>Clearly they are wrong. I need to get, respectively 11Jan2006 and
>Wednesday 11 January 2006.
One needs to avoid using US-designed date & time routines, unless one is
American. They've an excessive fondness for FFF; and for interpreting
anything as being valid if at all possible, without caring too much
about the result.
Best to use ISO 8601 YYYY-MM-DD; but many applications don't like that
separator, so use YYYY/MM/DD - many applications understand that, none
AFAIK misunderstand it, some may reject it.
Literal dates in VB can be written as #2006/01/11# for 2006 Jan 11th
everywhere.
You can use a RegExp, probably, to verify that you have ##/##/#### and
convert it to YYYY/MM/DD (and so can those using FFF); if you can split
into three numeric fields and use DateSerial (an under-appreciated
routine).
You can also output MM/DD/YYYY yourself from a CDate, using Year, Month,
Day, and a leading zero function. Your code then gives the format you
need regardless of localisation.
The following may help :
<URL:
http://www.merlyn.demon.co.uk/vb-dates.htm>
<URL:
http://www.merlyn.demon.co.uk/js-dates.htm>
<URL:
http://www.merlyn.demon.co.uk/datelinx.htm>
Note : VB has a function apparently giving ISO 8601 week numbers. It's
OK, if you can tolerate 3 errors per 28 years (AFAIK, it's not been
corrected); see vb-dates.htm for a demo & for good code.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:
http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:
http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.