Page 1 of 1
Date Time Picker - How can I choose BOTH a date and a time? Date Time Picker - getting both a date and a time.
#2
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 13 December 2007 - 10:33 PM
Hello All,
I'm fairly new to VB.NET, and I'm trying to use the Date Time Picker control.
I'd like to be able to select both a date and time.
When I click the selector arrow, and the calendar comes up, there seems to be no mechanism to also select a time.
Any ideas?
Thanks
Kent
I'm fairly new to VB.NET, and I'm trying to use the Date Time Picker control.
I'd like to be able to select both a date and time.
When I click the selector arrow, and the calendar comes up, there seems to be no mechanism to also select a time.
Any ideas?
Thanks
Kent
#3
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 13 December 2007 - 11:10 PM
Yes, when I first used this control I didn't think it made much sense to call it DateTime picker without the ability to select a time.
Try using a TextBox, then convert the value into a DateTime instance if need be, thats how I'd do it anyway.
Replace TextBox1 with the textbox you'd like to use obviously.
Try using a TextBox, then convert the value into a DateTime instance if need be, thats how I'd do it anyway.
Dim dteTime As Date = Convert.ToDateTime(TextBox1.Text)
Replace TextBox1 with the textbox you'd like to use obviously.
#4
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 13 December 2007 - 11:41 PM
The dateTimePicker can indeed do time. Hence the name 
Just change the Format property to time, and the ShowUpDown to True.
Either in the editor, or in code like
Just change the Format property to time, and the ShowUpDown to True.
Either in the editor, or in code like
dateTimePicker1.Format = Time dateTimePicker1.ShowUpDown = True
#7
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 29 June 2009 - 12:22 PM
For the DateTimePicker, I am trying to set a time to it, but it keeps defaulting to the current time.
I even tried this:
- On the form load,
TextBox1.Text = "01/01/2009 3:55 PM"
- In a button:
dtNextRunTime.Value = CType(TextBox1.Text.ToString, DateTime)
When I click the button, nothing happens, the dtNextRunTime control remains the same.
HOWEVER, if I make any kind of change to the textbox at runtime, then click the button, the dtNextRunTime control updates. Any ideas?!?
I even tried this:
- On the form load,
TextBox1.Text = "01/01/2009 3:55 PM"
- In a button:
dtNextRunTime.Value = CType(TextBox1.Text.ToString, DateTime)
When I click the button, nothing happens, the dtNextRunTime control remains the same.
HOWEVER, if I make any kind of change to the textbox at runtime, then click the button, the dtNextRunTime control updates. Any ideas?!?
#8
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 29 June 2009 - 05:54 PM
Are you trying to set to the current time when a user picks the date or some other specific time, or do you want to have the user pick the time?
If you want the user to pick the date and time, have one datetimepicker for date and another for the time. Then put both in one date variable.
If you have a time in mind (the time at form_load, the time when the user picks the date, a static time, etc) you can have a date variable store the time you want, and then put the month / date / year from the datetimepicker in that variable after the user selects it.
You can put the date and time in one variable either by using the Format method like:
or you can put in a date variable with Parse like this (d is your selected date variable from your datetimepicker):
Cheers!
Erick
If you want the user to pick the date and time, have one datetimepicker for date and another for the time. Then put both in one date variable.
If you have a time in mind (the time at form_load, the time when the user picks the date, a static time, etc) you can have a date variable store the time you want, and then put the month / date / year from the datetimepicker in that variable after the user selects it.
You can put the date and time in one variable either by using the Format method like:
MyString= Format(MyDate, "M/d/yyyy") & " 11:59:59 PM" ' or whatever time
or you can put in a date variable with Parse like this (d is your selected date variable from your datetimepicker):
Dim MyDate As Date = Date.Parse(CStr(d.Month) & "/" & CStr(d.Day) & "/" & CStr(d.Year) & " 00:00:00.000") ' or whatever time
Cheers!
Erick
#10 Guest_Bryan*
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 12 May 2010 - 06:34 PM
#12
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 13 May 2010 - 03:12 AM
That should work by default. Just use the right arrow key to move over to AM/PM and the up/down arrow KEY will change it, or the scroll arrows on the control will change it. You can also type A or P while selected to change it.
Page 1 of 1

Reply



MultiQuote








|