Page 1 of 1

DateTime & MySQL

Posted: Sat Jul 21, 2007 10:47 am
by iceangel89
How do i insert a DateTime into a MySQL DateTime Field? i seem to always get some funny time like "Thursday 01st of January 1970 08:03:27 AM" when its "21 July 2007 11:46PM" -> How do i format it like this instead also?

by the way i am using Dreamweaver CS3, is there an easy way to insert a date rather than playing with code?

Posted: Sat Jul 21, 2007 10:50 am
by feyd

Posted: Sat Jul 21, 2007 9:33 pm
by iceangel89
nope seems like it didn't work for me still giving me dates that have past long time ago. like Thursday 01st of January 1970 08:03:27 AM Date & time are both wrong.

my code here:

Code: Select all

date_default_timezone_set('Asia/Singapore');
...
$date = time(); // i tried date("Y-m-d H:i:s"); also didn't work

// code Dreamweaver gave me, i added the UserID & Date parts time the INSERT
  $insertSQL = sprintf("INSERT INTO `to-do` (Title, Content, UserID, Date) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['Title'], "text"),
                       GetSQLValueString($_POST['Content'], "text"),
		       GetSQLValueString($_SESSION['UserID'], "text"),
                       GetSQLValueString($date, "date"));
and my database MySQL, field data type, i had TIMESTAMP & DATETIME, both gave me the same problem. i think if i can get the NOW() function to work, all would be fine. but the sprintf is the problem i dont get it.

Posted: Sat Jul 21, 2007 9:40 pm
by feyd
echo $insertSQL.

Posted: Sun Jul 22, 2007 4:41 am
by timvw
And notice that the values represents by %s, are not quoted....