VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Page 1 of 1
  • You cannot start a new topic
  • Reply Reply

Date Time Picker - How can I choose BOTH a date and a time? Date Time Picker - getting both a date and a time. Rate Topic: -----


#2 shirotaka  Icon User is offline

  • New D.I.C Head
  • Pip

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


Dream Kudos: 0

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

#3 RodgerB  Icon User is offline

  • D.I.C Lover
  • Icon

Reputation: 42
  • View blog
  • Posts: 2,246
  • Joined: 21-September 07


Dream Kudos: 2200

Expert In: Dot Net Technologies

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.

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 - 나야나 नयन:
  • Icon

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


Dream Kudos: 175

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

dateTimePicker1.Format = Time
dateTimePicker1.ShowUpDown = True



:alien:
Was This Post Helpful? 2

#5 RodgerB  Icon User is offline

  • D.I.C Lover
  • Icon

Reputation: 42
  • View blog
  • Posts: 2,246
  • Joined: 21-September 07


Dream Kudos: 2200

Expert In: Dot Net Technologies

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

Posted 14 December 2007 - 02: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
  • Pip

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


Dream Kudos: 0

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

Posted 14 December 2007 - 08: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
  • Pip

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


Dream Kudos: 0

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

#8 erickh  Icon User is offline

  • New D.I.C Head
  • Pip

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


Dream Kudos: 0

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:

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
  • Icon

Reputation: 103
  • Posts: 1,223
  • Joined: 17-April 07


Dream Kudos: 150

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

Posted 29 June 2009 - 06: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 - 06: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 - 06: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
  • Icon

Reputation: 286
  • Posts: 1,279
  • Joined: 25-September 09


Dream Kudos: 25

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

Page 1 of 1
  • You cannot start a new topic
  • Reply Reply


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users