Page 1 of 1

Incorrect datetime value: storing date from php in MySQL

Posted: Thu Nov 09, 2006 10:48 am
by amir
Hi,
I am trying to store date in the MySQL. Here is my code to get start time and end time(5 min later)

Code: Select all

$start = time();
$day=date("d",$start);
$year=date("y",$start);
$month=date("m",$start);
$hour=date("H",$start);
$min=date("i",$start);
$sec=date("s",$start);
$start = date("y-m-d H:i:s",$start);

$end=mktime($hour,$min+5,$sec,$month,$day,$year);
$end=date("y-m-day H:i:s",$end);
I have tried to add

Code: Select all

$start
and

Code: Select all

$end
to MySQL table with attribute type 'datetime' or 'timestamp'. I have tryed just a timestamp format(time()) or other formats for $start,$end values, but it always gives the error:
Incorrect datetime value: '06-11-09am06 07:44:11' for column 'end_time' at row 1

How to store date in MySQL?
We are running: PhpMyAdmin 2.8.2.4, MySQL 5.0, Php 5.1.6, Apache 2.0.5.8

Thank You,

Posted: Thu Nov 09, 2006 10:55 am
by Luke
good luck with that.. :roll:

Posted: Thu Nov 09, 2006 12:49 pm
by RobertGonzalez

Code: Select all

SELECT NOW();
That will give you a datetime. Why not use the database to handle dates and times instead of the app? You might also want to search the MySQL manual for Date and Time Functions to see what is available to you.