date and time field

Results 1 to 3 of 3

Thread: date and time field

  1. #1
    Join Date
    Dec 1969

    Default date and time field

    Good morning all, I have a asp question: how to convert the string "01/12/1985 09:27 PM" to date and time? The field is date/time in sql server, the user picks up the date and time from a calendar and the string then will be on a text box, but how to convert it to a date and time filed using vbscript to match the database's? thanks a lot!

  2. #2
    Join Date
    Dec 1969

    Default Huh?

    sql = "INSERT INTO yourTable (yourDateField) VALUES (&#039;" & Request.Form("yourDateTextBox") & "&#039;)"<BR><BR>connectionObject.Execute sql

  3. #3
    Join Date
    Dec 1969

    Default RE: date and time field

    You&#039;ve got a couple of problems.<BR>"01/12/1985 09:27 PM"<BR>That MM/DD/YYYY or DD/MM/YYYY?<BR>More importantly, how does your script know that?<BR><BR>Secondly, as you yourself said - the field is datetime in SQL Server. It&#039;s not a string. As long as you pass it a string that SQL Server can understand (and will definitely not confuse between MM/DD and DD/YY, for example), then it won&#039;t matter.<BR><BR>If your question is how to splip up the string, then there are loads of different ways. You could attempt to use the Session.LCID property ot set the LCID of the script, and then use the CDate() function to try and get a valid date string. Alternatively you could avoid that completely and use string-handling functions to parse the string and then use DateSerial to get your date function (avoiding any possible issues with localisation settings).<BR><BR>Craig.

Posting Permissions

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