VS 2010 [RESOLVED] Getting only Time from datetimepicker-VBForums
Results 1 to 4 of 4

Thread: [RESOLVED] Getting only Time from datetimepicker

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2011
    Posts
    31

    Resolved [RESOLVED] Getting only Time from datetimepicker

    Hi guys,

    I'm having a little problem trying to figure out how to get only the time from a datetimepicker.

    I've set up a datetimepicker to only allow user selection of time by setting Format to Time and ShowUpDown to True.

    However, when I store the value of the datetimepicker to a variable, it returns a date as well.

    vb.net Code:
    1. JustTime = DateTimePicker1.Value

    I tried to get around the issue by using:

    vb.net Code:
    1. JustTime = DateTimePicker1.Value.hour & ":" & DateTimePicker1.Value.minute & ":" & DateTimePicker1.Value.second

    However, this seems like a really inelegant solution and I can't figure out how to get an AM/PM behind that.

    I feel like I'm missing some really simple solution that I'm just not seeing! There HAS to be a way to get just the time!

    If anyone could help me out, it would be most appreciated!

  2. #2
    Frenzied Member make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    1,916

    Re: Getting only Time from datetimepicker

    vb Code:
    1. DateTimePicker1.Value.tostring("HH:mm:ss")
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2011
    Posts
    31

    Re: Getting only Time from datetimepicker

    Quote Originally Posted by make me rain View Post
    vb Code:
    1. DateTimePicker1.Value.tostring("HH:mm:ss")
    Thank you for the reply, make me rain. That is definitely way neater than my method, but it still doesn't display am/pm.

    Edit: I don't know why I didn't think of this before, but I just tried DateTimePicker1.text and it worked!!!!

  4. #4
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: Getting only Time from datetimepicker

    Code:
    DateTimePicker1.Value.ToLongTimeString()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.