Results 1 to 9 of 9

Thread: DateTimepicker format

  1. #1
    nl2ttl is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Nov 2006
    Posts
    16
    Reputation
    98

    DateTimepicker format

    How can i get only the date in a variable or textbox from a datetimepicker?

  2. #2
    tylerwick is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Nov 2006
    Posts
    7
    Reputation
    0
    Heres what I did, there might be a another solutuion though

    I assigned that to a Button

    Code:
    lblDate.Text = cal.SelectionEnd

  3. #3
    nl2ttl is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Nov 2006
    Posts
    16
    Reputation
    98
    Hmm this is not working for me.

  4. #4
    tylerwick is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Nov 2006
    Posts
    7
    Reputation
    0
    Sorry I was thinking calendar,

    try this
    Code:
    lblDate.Text = DateTimePicker1.Value.Today
    It will be in Slash Format, theres a number of things you can do

    In Visual Studion a Popup with different Properties will come up when you put in that last period, (After Value)

    EDIT:
    Value.Date would probably suit you better

  5. #5
    Raven65's Avatar
    Raven65 is offline VB.NET Forum Master
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Oct 2006
    Posts
    305
    Reputation
    130
    Just call out the part that you want:

    Code:
    MessageBox.Show(Me.DateTimePicker1.Value.Date)
    

  6. #6
    cjard's Avatar
    cjard is offline VB.NET Forum All-Mighty
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2006
    Posts
    7,036
    Reputation
    1720
    Quote Originally Posted by nl2ttl View Post
    How can i get only the date in a variable or textbox from a datetimepicker?
    To get it in the DTP itself, set the format to Custom, and write your own formatting string. To put a customised form of the date into a label or textbox string, use the .Value property of the datetimepicker which will give you the DATE value in the control. You can then ToString() this:

    Dim s as String = dtp.Value.ToString("yyyyMMdd")


    DO NOT attempt to use this as a date because it is now a string, not a date - if you need the date for something, go back to the dtp and get its value again.

  7. #7
    Nicezia is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Mar 2009
    Posts
    1
    Reputation
    0
    if you wanted to change the textbox's text back into a date you could Date.Parse(Textbox.Text)

  8. #8
    winstongel is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    May 2013
    Posts
    1
    Reputation
    0
    you can retrieve it in string also..

    Dim idate As String
    idate = DateTimePicker1.Value


    wgel.

  9. #9
    jmcilhinney's Avatar
    jmcilhinney is online now VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    12,859
    Reputation
    1623
    Quote Originally Posted by winstongel View Post
    you can retrieve it in string also..

    Dim idate As String
    idate = DateTimePicker1.Value


    wgel.
    That's very bad code. It would only compile with Option Strict Off for a start. If you wanted a String then you would either get the Text property of the control or else call ToString or the like on the DataTime that you get from the Value property, as has been shown.

    Apart from that, please don't resurrect threads that are over four years old without very good reason.

Bookmarks

Posting Permissions

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