Dear All,
I have a VB 6.0 program using DateTimePicker Control(DTP).
The purpose of DTP is for User to search record within the range of starting
date and ending date.
User need the date as "dd/MM/yyyy" format in the DateTimePicker Control.
My PC is running on Window XP.
Regional and Language setting is English(US) with short date format is in
"dd/MM/yyyy" format.
With the below code, DTP display the date correctly on my PC.
The program also installed on another PC with Window 2000 Pro.
Regional and Language setting is the "dd/MM/yyyy".
Previously it can generate the expected result until 01/10/2007(1st Oct 2007).
Since that day, 1st Oct 2007 display as 10/01/2007 in DTP.
Example:
dtFromDate.Value = 10/01/2007
dtToDate.Value = 10/02/2007
When dtFromDate is dropdown, it show current selection is 10th January 2007.
When dtToDate is dropdown, it show current selection is 10th February 2007.
The program also save date as 10th January 2007 instead of 1st October 2007.
Private Sub Form_Load()
dtFromDate.Value = Format(Date, "dd/MM/yyyy")
dtToDate.Value = Format(Date + 1, "dd/MM/yyyy")
dtFromTime.Format = dtpTime
dtFromTime.Value = "08:00:00 AM"
dtToTime.Format = dtpTime
dtToTime.Value = "08:00:00 AM"
End Sub
I get back the program and test out on my PC, it work correctly.
Why the same exe can work at my PC but not at User PC?
Why it can work until 30th September but got problem after that?
Could anyone shed some light?
Thank you.

Signature
Novice
Dave O. - 11 Oct 2007 10:05 GMT
Poor thing is confused, you have US regional settings but UK date format.
There probably is a simple resolution but why not use "MMM" for the month
then it will give a totally unambiguous "Jan" or "Oct" for the month instead
of "01" or "10".
Dave O.
> Dear All,
>
[quoted text clipped - 44 lines]
>
> Thank you.
Victor Koch - 11 Oct 2007 13:43 GMT
Hi Vista,
Try this
Private Sub Form_Load()
dtFromDate.Format = dtpCustom
dtFromDate.CustomFormat = "dd/MM/yyyy"
dtToDate.Format = dtpCustom
dtToDate.CustomFormat = "dd/MM/yyyy"
dtFromDate.Value = Date
dtToDate.Value = Date + 1
dtFromTime.Format = dtpTime
dtFromTime.Value = "08:00:00 AM"
dtToTime.Format = dtpTime
dtToTime.Value = "08:00:00 AM"
End Sub
--
Víctor Koch.
> Dear All,
>
[quoted text clipped - 42 lines]
> --
> Novice
Bob Butler - 11 Oct 2007 14:12 GMT
> Hi Vista,
>
[quoted text clipped - 16 lines]
>
> End Sub
You may also want to avoid the string-to-date conversions on the times; it's
less of a problem than the dates but is still a potential issue:
dtFromTime.Format = dtpTime
dtFromTime.Value = #8:00:00 AM#
dtToTime.Format = dtpTime
dtToTime.Value = #8:00:00 AM#
MikeD - 11 Oct 2007 13:47 GMT
> Dear All,
>
[quoted text clipped - 42 lines]
> Why it can work until 30th September but got problem after that?
> Could anyone shed some light?
Don't format the date when you're assigning it. There's absolutely no reason
whatsoever to do this. The Date function returns a Variant of subtype Date,
which is exactly what the Value property of the DTP expects. Formatting the
date and then assigning it is possibly the cause of the ambiguity.
If you want the DTP to display the date using a specific format, then set
its Format property (you can use the CustomFormat if you want a format other
than the system-defined short date or long date).

Signature
Mike
Microsoft MVP Visual Basic