Click to See Complete Forum and Search --> : PHP MySQL Date format Conflict


GUIR
03-13-2008, 05:09 AM
Hello,

I inserted a date into mysql database Date type field as string in dd/mm/yyyy format.

example:


...

$arrival = '10/03/2008';
...
...



But when I query database records I get inserted date items as 0000-00-00.

I tried to solve this using many functions, but didn't work (strtotime, getdate, mktime, etc)

Could someone please let me know how to navigate between dates of PHP & MySQL.

I want to keep MySQL data type as Date because I need to query between dates later. Accordingly I will need date conversion extensively between PHP to MySQL and vice versa.

Thanks & Best Regards

MrCoder
03-13-2008, 07:17 AM
Insert the date in the same format as MySQL uses.

YEAR-MONTH-DAY

2008-03-13

chazzy
03-13-2008, 07:51 AM
Actually, that's just how MySQL displays the date. The data is typically stored in a much different format.

From PHP's end, you should just be formatting the data is it's returned to you in a way you like, than trying to force MySQL to format it for you.

GUIR
03-13-2008, 11:58 PM
It worked after I format PHP string as YYYY-MM-DD format.

Thanks for your guidance.

Huevoos
03-14-2008, 12:13 AM
I'd rather get the date using php's time() function and store it in mysql using UNIXTIMESTAMP()