Discussion:
Date format problem in VB6.0
(too old to reply)
Linda
2004-11-01 12:51:30 UTC
Permalink
Hi all,
I have a simple problem. I understand that the system date is in the format
mm/dd/yy.
Now in my VB application, I am converting the format entered by the user to
this mm/dd/yy type using CDate.
But the CDate function doesn't seem to work properly.

If suppose I enter 05/11/2001, which should be read as 11 May, is being
taken as 5 Nov. This problem does not occur if either of the two (month or
date) is larger than 12. for eg, 1/14/2001 will always be taken as 14th of
January.

Any ideas how to overcome this issue?

Thanks a lot !
Jason Keats
2004-11-01 13:21:51 UTC
Permalink
Post by Linda
Hi all,
I have a simple problem. I understand that the system date is in the
format mm/dd/yy.
Now in my VB application, I am converting the format entered by the
user to this mm/dd/yy type using CDate.
But the CDate function doesn't seem to work properly.
If suppose I enter 05/11/2001, which should be read as 11 May, is
being taken as 5 Nov. This problem does not occur if either of the
two (month or date) is larger than 12. for eg, 1/14/2001 will always
be taken as 14th of January.
Any ideas how to overcome this issue?
Thanks a lot !
Have you checked Control Panel > Regional Options > Date to see whether
dd/MM/yyyy is being used as the short date format?

If it is, then what you describe would make perfect sense. 05/11/2001 should
be read as 5 Nov 2001 where I live. Where do you live?

HTH
YYZ
2004-11-01 14:10:31 UTC
Permalink
Post by Linda
Hi all,
I have a simple problem. I understand that the system date is in the format
mm/dd/yy.
Not always. In fact, under the covers, VB doesn't store dates this way at
all. It stores it as a number, a double to be precise.
Post by Linda
Now in my VB application, I am converting the format entered by the user to
this mm/dd/yy type using CDate.
I would convert it to the format of yyyy/mm/dd -- this is unambiguous when
using it with Access and SQL Server and in VB, too.
Post by Linda
But the CDate function doesn't seem to work properly.
It is working properly. You are passing it an ambiguous date. Check your
locale settings like Jason said, but even so, you don't need to worry about
your personal, or anyone else's, locale settings. Grab your month/day/year
textbox values (I'm assuming you hav those split up? If not, then there are
other issues...) and build a string in the format that I mentioned. Then
call CDate on it. After that, VB stores it happily and unambiguously as a
double.

Matt
Kjell
2004-11-01 16:24:04 UTC
Permalink
Linda

There are ways to handle different regional date settings probably very nice
but I found it to make a mountain out of a single stone.

I solved it with these simple rules.

1. In code handle all dates either in a Date variable or in a string as a
fully qualified format "yyyy-mm-dd", This format works fine with SQL and it
works worldwide.
Your date handling in code will never fail and you got all you need.

2. for display on screen either force it as you want it or let each regional
system has it's effect.

3. The only thing you have to be careful with is users date input, and this
can be solved in many different ways depending on what you need and the
impact is has if it becomes wrong.

voila, no more problem, my application works fine even when users decide to
make my life hard by altering the regional settings to something custom.
The same application is used all over Europe, most dates on screen are
according to each users regional settings just by using Format(Date) or even
just by using date variable.


Kjell
Post by Linda
Hi all,
I have a simple problem. I understand that the system date is in the format
mm/dd/yy.
Now in my VB application, I am converting the format entered by the user to
this mm/dd/yy type using CDate.
But the CDate function doesn't seem to work properly.
If suppose I enter 05/11/2001, which should be read as 11 May, is being
taken as 5 Nov. This problem does not occur if either of the two (month or
date) is larger than 12. for eg, 1/14/2001 will always be taken as 14th of
January.
Any ideas how to overcome this issue?
Thanks a lot !
Continue reading on narkive:
Loading...