Thursday, March 13, 2008

VB6 date conversions

Came across a problem with converting strings into dates in a VB6 app. Basically our date strings were in the format of "MM/dd/yyyy" but after using CDate(...) to convert the string in that format into a date it would have different results depending on the string itself. For example, for a "01/13/2008" CDate(...) would return the correct date of 13th Jan 2008. However, given a "01/12/2008" it would produce 1st Dec 2008.

I am guessing this behavior probably has something to do with my regional settings as well but I gave up trying to figure that part and just started using VB6 DateSerial(year, month, day) function to create my dates. Works wonderfully. Wish I had seen it before.

No comments: