Date Time Picker - How can I choose BOTH a date and a time?

Date Time Picker - getting both a date and a time.

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 118569 Views - Last Post: 11 May 2013 - 10:00 PM Rate Topic: -----

Replies To: Date Time Picker - How can I choose BOTH a date and a time?

#2 shirotaka  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 2
  • Joined: 13-December 07

Re: Date Time Picker - How can I choose BOTH a date and a time?

Posted 13 December 2007 - 11: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
Was This Post Helpful? 1

#3 RodgerB  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 66
  • View blog
  • Posts: 2,284
  • Joined: 21-September 07

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.

Dim dteTime As Date = Convert.ToDateTime(TextBox1.Text)



Replace TextBox1 with the textbox you'd like to use obviously. :)
Was This Post Helpful? 1

#4 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 31
  • View blog
  • Posts: 824
  • Joined: 14-November 07

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

dateTimePicker1.Format = Time
dateTimePicker1.ShowUpDown = True



:alien:
Was This Post Helpful? 2

#5 RodgerB  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 66
  • View blog
  • Posts: 2,284
  • Joined: 21-September 07

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


:alien:
Was This Post Helpful? 0
  • +
  • -

#6 shirotaka  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 2
  • Joined: 13-December 07

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
Was This Post Helpful? 0
  • +
  • -

#7 Sep22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-June 09

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?!?
Was This Post Helpful? 0
  • +
  • -

#8 erickh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 24-June 09

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:

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
Was This Post Helpful? 0
  • +
  • -

#9 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

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
Was This Post Helpful? 0
  • +
  • -

#10 Guest_Bryan*


Reputation:

Re: Date Time Picker - How can I choose BOTH a date and a time?

Posted 12 May 2010 - 07:34 PM

View PostNayana, on 13 December 2007 - 11:41 PM, said:

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

dateTimePicker1.Format = Time
dateTimePicker1.ShowUpDown = True



:alien:

Was This Post Helpful? 0

#11 Guest_Bryan*


Reputation:

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.
Was This Post Helpful? 0

#12 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

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.
Was This Post Helpful? 0
  • +
  • -

#13 TomServo3k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-March 10

Re: Date Time Picker - How can I choose BOTH a date and a time?

Posted 09 August 2011 - 02:51 PM

View Postshirotaka, 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 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)
Was This Post Helpful? 0
  • +
  • -

#14 joemasmil  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-February 12

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.
Was This Post Helpful? 0
  • +
  • -

#15 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Date Time Picker - How can I choose BOTH a date and a time?

Posted 13 February 2012 - 04:52 AM

datetimepicker2.value = datetimepicker1.value.addhours(12) 

Here's a list of other methods available from the datetime object

This post has been edited by CharlieMay: 13 February 2012 - 04:55 AM

Was This Post Helpful? 1
  • +
  • -

#16 joemasmil  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-February 12

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
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2