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
Date Time Picker - How can I choose BOTH a date and a time?Date Time Picker - getting both a date and a time.
16 Replies - 96133 Views - Last Post: 11 May 2013 - 10:00 PM
Replies To: Date Time Picker - How can I choose 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 - 11:33 PM
#3
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 14 December 2007 - 12:10 AM
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 14 December 2007 - 12:41 AM
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
#5
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 14 December 2007 - 03:50 AM
Thanks for that Nayana! That explains it...
intIntelligence += 1
#6
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 14 December 2007 - 09:35 AM
Thanks for the info.
I suppose the DateTimePicker is a Date OR Time picker, but not both.
Kent
I suppose the DateTimePicker is a Date OR Time picker, but not both.
Kent
#7
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 29 June 2009 - 01: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 - 06: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
#9
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 29 June 2009 - 07:31 PM
TRY OUT THE CUSTOM FORMAT
#10 Guest_Bryan*
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 12 May 2010 - 07:34 PM
#11 Guest_Bryan*
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 12 May 2010 - 07:37 PM
How can I use the spin button to set the AM/PM when the format is set to time. Clicking the up or down when AM/PM selected does nothing.
#12
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 13 May 2010 - 04: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.
#13
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 09 August 2011 - 02:51 PM
shirotaka, on 13 December 2007 - 10:33 PM, said:
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
I realize this is an old request but since I have solved it and don't see it fully explained, here goes.
You must use a CustomFormat which includes date and time formatting, such as "yyyy-MM-dd HH:mm" AND ALSO select Format = "Custom" (the default is Long)
#14
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 13 February 2012 - 04:15 AM
how can i add 12hrs from 1 datetimepicker using time Format and show the output in another datetimepicker?? ex . 8:00:00 PM becomes 8:00:00 AM when you add 12hrs.
#16
Re: Date Time Picker - How can I choose BOTH a date and a time?
Posted 13 February 2012 - 08:19 AM
how to count items in listview and put the output in a label
|
|

New Topic/Question
Reply



MultiQuote






|