What is the best way to insert a date field into a mysql database through PHP,
ive tried DATE()
and <?php echo date("j/n/y h:i a");?>
however sometimes these dont work right.
DATE
Moderator: General Moderators
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
You should have this in mind, delaing with the timestamp type in the database:
Result:
As I prefer using timestamp's, and later use date() ( or whatever ) PHP function to format it, I need to use the MySQL's unix_timestamp() function.
More here: http://dev.mysql.com/doc/mysql/en/Date_ ... tions.html
Code: Select all
echo time()."<br />";
$result = mysql_fetch_assoc(mysql_query("select NOW() as timetest"));
print_r($result);
$result = mysql_fetch_assoc(mysql_query("select unix_timestamp(NOW()) as timetest"));
print_r($result);Code: Select all
1084317560
Array
(
їtimetest] => 2004-05-12 01:20:04
)
Array
(
їtimetest] => 1084317604
)More here: http://dev.mysql.com/doc/mysql/en/Date_ ... tions.html