Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php/Mysql date saved as '0000-00-00'

Tags:

date

php

mysql

I have a Mysql database where i keep dates of the clients orders.

Date is generated by a php function date('Y-m-d'). Two records in my database have values '0000-00-00'. One was created by a client from Australia and another by a client from Italy. Other 5000 orders are fine.

My question is how is it possible to generate such date ? Could it be something with individual browser settings ?

Thanks for help

like image 275
gniewleone Avatar asked Jan 08 '13 12:01

gniewleone


2 Answers

The only reason what i can find is either your client has entered improper date format or he has entered an empty string. Remember the date format in Mysql is yyyy-mm-dd.

like image 86
Php Geek Avatar answered Oct 23 '22 07:10

Php Geek


I noticed I was having the same exact issue, and it turned out it was simply that I didn't put single quotes around my $date variable when inserting it, thus it was inserting a null or blank value which appeared as 0000-00-00 in the database. Once I put '$date' instead of $date in my insert statement, the value appeared as expected.

like image 26
ThisGuy Avatar answered Oct 23 '22 08:10

ThisGuy