Date literal bigotry

Posted Thu, Jul 8 2004 7:02 by bill

In VB6, if I declared a variable as a Date, I could then assign a literal to it such as :

Dim dt as Date
dt = #30 Jun 2004#

The IDE would change that to #6/30/2004#.  This was always a bit of an annoyance, and you could tell it was American based, not European or Australian.  In fact I always have that issue with American dates, when the numbers could be interpreted either way, eg 4/8/2004. Is that August or April?  Depends on where you are ;)

VB generally is really good with Dates at runtime, as it is local aware.  At design time though, it’s just plain bigotry.  Vb.NET is actually worse than VB6, as VB.NET does not even parse the literal. That is, it doesn’t recognize #30 Jun 2004#.

I really wish they would fix this and allow for date literals to be less ambiguous, and allow not only the entering in of dates as #30 Jun 2004#, but also allow for that format to be preserved and applied to all date literals.  Why? Well because it is non ambiguous!

Filed under: , ,

Comments

# U.S.-centric dates and localized languages

Thursday, July 08, 2004 5:37 PM by TrackBack

Je ne parle pas Francais.

# re: Date literal bigotry

Thursday, July 08, 2004 8:35 PM by bill

Hi Bill,

<resisting urge to make big date processing whinge>

While they're at it, they need to take a long hard look at functions like IsDate(). Either 27/12/04 is a date or 12/27/04 is a date. They're not both dates. I came across someone the other day who'd loaded 60 million rows into a database table, thought they were in US format, they were in Oz format. DTS (which uses the VBA functions) just loaded the lot without a whinge. Bit of a pity that 2/3 of them had the month and day reversed though. Bigger pity that it was only noticed 3 days into production when people started saying "that's not when that happened". Try to fix it then after days of real production...

Compare that to an error at row 3 of the load. I'll take the latter every time.

</resisting urge to make big date processing whinge>

Regards,

Greg

# re: Date literal bigotry

Thursday, July 08, 2004 10:56 PM by bill

Hey Greg,

Yeh, IsDate does have some wierd behaviour. It is localized, but it also assumes that if a date has the form of x/y/z then if:
(x > 12 AndAlso y <= 12) OrElse (y > 12 AndAlso x <=12)
then it's potentially a date.
That is, if you enter in 12/30/2004 it will be interpreted as 30 Dec, 2004 where ever you are. CDate does the same.

The good news is in Whidbey, the DateTime Structure has a TryParse method, so I would recommend using that ;) Tat will also let you control which culture is used.

# re: Date literal bigotry

Friday, July 09, 2004 1:09 AM by bill

Maybe something like VFP has: {^yyyymmdd} translates to the currently specified date format in the application.