DateTime & MySQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
iceangel89
Forum Commoner
Posts: 39
Joined: Mon Jul 02, 2007 7:02 pm

DateTime & MySQL

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

iceangel89
Forum Commoner
Posts: 39
Joined: Mon Jul 02, 2007 7:02 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

echo $insertSQL.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

And notice that the values represents by %s, are not quoted....
Post Reply