#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    116
    Rep Power
    11

    Exclamation ToString Method for Saving Datetime value


    how can i save date and time using ToString() Method of datetime picker in vb.

    dtFrom.Value.ToString("MM/dd/yyyy") // currently i m using this but it will not give me time part. which is also mandatory for me.

    required format is month day year hour min sec am/pm

    my time part is always zero by using above code i can't find format strings for time part. need assistance.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    45
    The date and time is stored as a Double Precision number relative to a particular start date (can't recall what that is at the moment). The part in front of the decimal point is the date, and the part behind is the time. It can be displayed in any different number of ways, the easiest being the system settings (long , medium, or short). The code below is VB6, but .Net will be similar.
    Code:
    Private Sub Command1_Click()
        Dim dblDateTime As Double
        dblDateTime = Now
        Debug.Print dblDateTime
        Debug.Print CStr(dblDateTime)
        Debug.Print CDate(dblDateTime)
        Debug.Print Format(dblDateTime, "MM/dd/yyyy hh:mm:ss AM/PM")
    End Sub
    
    resulting in:
     41289.462650463 
    41289.462650463
    01/15/13 11:06:13 AM 
    01/15/2013 11:06:13 AM
    J.A. Coutts

IMN logo majestic logo threadwatch logo seochat tools logo