1

This variable gets inserted into my mysql database:

$n_date = date('d-m-Y');

and in the database i always see this:

0000-00-00 00:00:00

What am i doing wrong?

1
  • Why not just use NOW() within your SQL? Commented Mar 14, 2013 at 20:59

4 Answers 4

2

Because your format is wrong. MySQL expects the date to be in YYYY-MM-DD format. So:

$n_date = date('d-m-Y');

should be

$n_date = date('Y-m-d');

Or, for completeness:

$n_date = date('Y-m-d H:i:s');
Sign up to request clarification or add additional context in comments.

Comments

1

You will need to format dates for insert into MySQL as yyyy-mm-dd.

Comments

1

Your format is incorrect. Why not just INSERT NOW()?

INSERT INTO tbl (dateCol) VALUES (NOW())

Comments

0
$n_date = date('YYYY-mm-dd hh:ii:ss');

Insert that way.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.