Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Time Picker - Strange Behavior 1

Status
Not open for further replies.

Foada

Programmer
Feb 4, 2002
1,110
US
Has anyone else seen this happen. If you drop a Date Time Picker control on a form along with a text box and then use this code:
Code:
Private Sub DTPicker1_Change()
    Text1.Text = DTPicker1.Value
End Sub

Set the Date Time Picker Up Down property to true and the format to dtpTime, run the app and use the up or down to run the Date Time Picker through 12:00:00 AM by just changing the hour. The date and time should be displayed for all values except 12:00:00 AM which just display the date in the textbox. I tried this on a couple of machines with different versions of the Date/Time picker control with the same results. Do I have something buggy or is this an undocumented feature of the control? [spin]

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
This is not a bug, but the default behaviour of the string representation of Date data type, which hides the time portion at 12:00:00 AM, just to simplify the Date representation. An exception to this rule is an uninitialized date variable, which always shows the time portion (12:00:00 AM) and hides the date portion.

In order to get the full date/time, you can format the value returned from the DTPicker control.
___
[tt]
Private Sub DTPicker1_Change()
Text1.Text = Format$(DTPicker1.Value, "m/d/yyyy hh:nn:ss AMPM")
End Sub[/tt]
___

Note that this behaviour is not a flaw or bug. It helps when you are manipulating dates only. In that case, the time is assumed to be 12:00:00 AM and hidden automatically from the string representation of the date.

Try the following commands in the Immediate window.
[tt]
?Date
7/12/2005
?format$(Date,"m/d/yyyy hh:nn:ss AMPM")
7/12/2005 12:00:00 AM
[/tt]
You can see that the Date property, which returns the current date also contains a time portion (12:00:00 AM) which is hidden as a result of this behaviour, thus making it convenient to manipulate the dates without bothering about the time.
 
Hypetia,

Thank you for the info. I figured it was going to be something like that. I have never had a problem with it in VB as I always perform the formatting there. I just happen to notice it when I was using the control from Wonderware. Thanks for you help. [spin]

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top