Adam_930
asked on
VB.NET DateTimePIcker Time ONLY
I am trying to use only the time portion of a DateTimePicker.
I want to populate multiple DateTimePickers with different times
From what I've seen, I have to set a date as well as a time, even though I have the format set to Time.
DateTimePicker0.Value = "7/24/2014 9:01 AM"
Is there a way to set only the time?
something like:
DateTimePicker0.Value = "9:01 AM"
thanks,
I want to populate multiple DateTimePickers with different times
From what I've seen, I have to set a date as well as a time, even though I have the format set to Time.
DateTimePicker0.Value = "7/24/2014 9:01 AM"
Is there a way to set only the time?
something like:
DateTimePicker0.Value = "9:01 AM"
thanks,
Please see the following Microsoft documentation for using a DateTimePicker for Time only, How to: Display Time with the DateTimePicker Control.
If you want to set the time, avoid null values by using todays date
If you want to preserve the date but only change the time use this
DateTimePicker1.Value = new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 5, 30, 0 )
If you want to preserve the date but only change the time use this
Dim Hour = 1
Dim Minute = 30
Dim Second = 5
DateTimePicker1.Value = new DateTime(DateTimePicker1.Value.Year, DateTimePicker1.Value.Month, DateTimePicker1.Value.Day, Hour, Minute, Second )
ASKER
esskayb2b:
I have done what you have suggested, but I want to populate the value of the time only from within code
DateTimePicker0.Value = "7/24/2014 7:01 AM"
Do I have to put in a date (even if fictitious) and then strip it back out when I execute my application?
What I was hoping to do is something like: DateTimePicker0.Value = "7:01 AM" because I am only dealing with time
I have done what you have suggested, but I want to populate the value of the time only from within code
DateTimePicker0.Value = "7/24/2014 7:01 AM"
Do I have to put in a date (even if fictitious) and then strip it back out when I execute my application?
What I was hoping to do is something like: DateTimePicker0.Value = "7:01 AM" because I am only dealing with time
ASKER
I am trying to understand how the .NET DateTimePIcker functions,, eventually the information for the DateTimePIcker will get it's information from a file that read when the user brings up the screen
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is there a better control to use than DateTimePIcker if I am dealing with just time?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or you could roll your own by inheriting from DateTimePicker and adding code to behave the way you need it to.
'The following code sample shows how to create a DateTimePicker that enables users to choose a time only.'
Open in new window
http://msdn.microsoft.com/en-us/library/ms229631.aspx