Bricked
Bricked

Reputation: 115

Cannot save today's date in mySQL column

This is a simple solution, but I cannot get it to work even after reading many similar posts on the topic.

I am able to define a php variable to hold the current date because I can echo it properly:

$_date_today = date('Y-d-m');
echo $_date_today;

2017-31-03

But when I try to use that php variable to insert the date value into mySQL table, the value inserted is 0000-00-00. My date_order column in the table is defined as DATE.

Upvotes: 2

Views: 88

Answers (2)

sameer kumar
sameer kumar

Reputation: 149

try to change the date format cause mysql format is Y-m-d and you are entering Y-d-m

try use this $_date_today = date('Y-m-d'); insted of $_date_today = date('Y-d-m');

Upvotes: 1

Dustin S
Dustin S

Reputation: 80

While mySQL always stores the date in the database using the same format and I don't believe it can be changed, you can format the date however you want when retrieving it using the many mySQL functions available... see the following link: mySQL date manimpulation functions

Upvotes: 1

Related Questions