Proper Date Time format for MySQL from classic ASP code

Published under ASP,MySQL,web design,web development. Tags: , , , .

To properly put the date and time into a MySQL date field, you need to put it into the format of:

yyyy-mm-dd hh:mm:ss

Here is some code to do this in classic ASP for input into a MySQL table:

Dim testdate, testmonth, testday, ISODate
testdate = Request.Form("frmField5")
testmonth = Right(Month(testdate),2)
testday = Right(Day(testdate),2)
ISODate = Year(testdate) & "-" & testmonth & "-" & testday & " " & hour(testdate) & ":" & minute(testdate) & ":" & second(testdate)

The ISODate variable is in the correct format to insert in a MySQL UPDATE or INSERT SQL statement. Below is an example SQL string to UPDATE a date field in a MySQL table:

UPDATE myTable SET thisdate = 'ISODate' WHERE myID = 'thisID'

VN:F [1.9.3_1094]
Rating: 9.7/10 (3 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)
Proper Date Time format for MySQL from classic ASP code, 9.7 out of 10 based on 3 ratings
 
Take a piece of the Web from WebPaws.com: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • MisterWong
  • Y!GG
  • Webnews
  • Digg
  • del.icio.us
  • StumbleUpon
  • De.lirio.us
  • eKudos
  • email
  • Facebook
  • Fleck
  • Google Bookmarks
  • Hype
  • LinkedIn
  • MySpace
  • Print
  • Technorati
  • YahooMyWeb

1 Comment to Proper Date Time format for MySQL from classic ASP code

  1. piano rentals,

    piano rentals…

    Hello ;) Thanks heaps for this indeed!… if anyone else has anything, it would be much appreciated. Great website Super Piano Links http://www.en.Grand-Pianos.org Enjoy!…

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: 0 (from 0 votes)

Leave a comment to this post


WebPaws.com is Digg proof thanks to caching by WP Super Cache