Hi all,

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.

HOWEVER!!! As soon as the first two characters of my date are 13 or more
then it understands correctly what my date is - that's because there's no
months greater than 13 so I guess it's assuming that I need the format
changed to d/m/y. Then as soon as the first two chars are 12 or less, then
it goes back to m/d/y.

Is there a fix for this?

Re: Bug? Date functions get day & month wrong by axtens

axtens
Thu Dec 29 23:02:57 CST 2005

It's a known irritation against which I bashed my head repeatedly
earlier this year. Set the machine for yankee dates and dates formatted
as dmy are visible as dmy. Change the machine to aussie dates and dates
formatted to dmy are visible as mdy. It sounds so ridiculous that I'm
starting to doubt my sanity.

Anyway, I worked around it by using ISO (yyyy-mm-dd) dates as much as I
could and even having conversion routines just to make sure that my
dates stayed within the realm of sanity.

Some of my functions are below. But what's of greater interest is
<http://www.aspfaq.com/show.asp?id=2260> which treats the whole issue
very nicely.

Regards,
Bruce.


Function MakeKey5( dKey )
Dim sNewKey, nYear, nMonth, nDay, nHour, nMinute, nSecond
nYear = Year( dKey )
nMonth = Month( dKey )
nDay = Day( dKey )
nHour = Hour( dKey )
nMinute = Minute( dKey )
nSecond = Second( dKey )
sNewKey = Join( Array( nYear, ZeroFill2( nMonth ), _
ZeroFill2( nDay ), _
ZeroFill2( nHour ), _
ZeroFill2( nMinute ), _
ZeroFill2( nSecond )), "." )
MakeKey5 = sNewKey
End Function

function MakeKey6( nYear, nMonth, nDay, nHour, nMinute, nSecond )
Dim sNewKey
sNewKey = Join( Array ( nYear, ZeroFill2( nMonth ), _
ZeroFill2( nDay ), _
ZeroFill2( nHour ), _
ZeroFill2( nMinute ), _
ZeroFill2( nSecond ) ), "." )

MakeKey6 = sNewKey
end function

Function KeyToDate( sKey )
Dim aKey
aKey = Split( sKey, "." )
KeyToDate = DateSerial( aKey( 0 ), aKey( 1 ), aKey( 2 ) ) + _
TimeSerial( aKey( 3 ), aKey( 4 ), aKey( 5 ) )
End Function

Function Zerofill2( nNum )
Zerofill2 = Right( "00" & nNum, 2 )
End Function

Function dbDate(dDate)
'~ http://www.aspfaq.com/show.asp?id=2260
dbDate = year(dDate) & "-" & _
zerofill2( month(dDate) ) & "-" & _
zerofill2( day(dDate) ) & " " & _
zerofill2( hour( dDate ) ) & ":" & _
zerofill2( minute( dDate ) ) & ":" & _
zerofill2( second( dDate ) )
End Function


Re: Bug? Date functions get day & month wrong by Dr

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.