Page 1 of 1
DATE
Posted: Thu Apr 22, 2004 9:42 am
by Niko
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.
Posted: Tue May 11, 2004 5:02 am
by malcolmboston
ok well insert time into the DB
їphp]
$number_time = time();
// run insert
ї/php]
then to format it in a page when returning the record
їphp]
$formatted_time = date ("g:ia - M j", $number_time);
ї/php]
would output the following
їcode]11:00am - May 1ї/code]
hope that helps
Posted: Tue May 11, 2004 6:23 pm
by JAM
You should have this in mind, delaing with the timestamp type in the database:
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);
Result:
Code: Select all
1084317560
Array
(
їtimetest] => 2004-05-12 01:20:04
)
Array
(
їtimetest] => 1084317604
)
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