Results 1 to 4 of 4

Thread: Save the date & time

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    76

    Save the date & time

    I am trying to save the date & time into a table in SQL. I am using the datetimepicker control of VB. But, by using this I can save either the date or the time .. not both at a time. How do I store both using a control & in only one column of SQL table.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Save the date & time

    Set the DatePicker Format and CustomFormat properties to allow the user to enter date and time.

    Code:
    Private Sub Form_Load()
        With DTPicker1
           .Format = dtpCustom
           .CustomFormat = "dd-MMM-yyyy hh:mm:ss"
           .Value = Now
        End With
    End Sub
    
    Private Sub DTPicker1_CloseUp()
        Debug.Print DTPicker1.Value
    End Sub
    As for saving to SQL, are you updating or inserting? Are you using stored procedures, inline sql statements or recordsets???

  3. #3

    Re: Save the date & time

    assuming that you are using an update query to perform this

    Code:
    strDate=Format(dtDate.value,"dd-MMM-yyyy" )
    strTime = dttime.value
    
    
    "update table set datetimecolumn = '"& strDate & " " & strTime &"' where " 'conditions here
    OR

    you can set the property of the datetime picker control
    to opt for
    format as 3 -dtpCustom
    and change the custom format text as dd-MMM-yyyy hh:mm:ss tt

    now you can have the date time in a same control

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Save the date & time

    Quote Originally Posted by pons
    assuming that you are using an update query to perform this

    Code:
    strDate=Format(dtDate.value,"dd-MMM-yyyy" )
    strTime = dttime.value
    
    
    "update table set datetimecolumn = '"& strDate & " " & strTime &"' where " 'conditions here
    OR

    you can set the property of the datetime picker control
    to opt for
    format as 3 -dtpCustom
    and change the custom format text as dd-MMM-yyyy hh:mm:ss tt

    now you can have the date time in a same control
    The query would depend on the database, and the data type of destination field.

Posting Permissions

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



Click Here to Expand Forum to Full Width