1

I have a column of type date (only date) in mysql. However, when I am using the following:

$Answer->dateCreated=date('d-m-y');

I'm getting an error

A non well formed numeric value encountered

Any idea??

1
  • 1
    without seeing your object code its any ones guess Commented Nov 17, 2011 at 3:13

4 Answers 4

3

MySQL's date format is yyyy-mm-dd, which in PHP would be date('Y-m-d'). Your format string is reversed and using 2 digit years instead of 4 - Y2k's old news by now... don't use 2 digit years anymore.

Sign up to request clarification or add additional context in comments.

Comments

1

I just did this and it is working:

$Answer->dateCreated = strtotime("now");

Comments

0

Try:

define('MYSQL_DATE_FORMAT', 'Y-m-d H:i:s');
$Answer->dateCreated = date(MYSQL_DATE_FORMAT);

I understand you're not wishing to save the time, don't worry MySQL will ignore the time for these columns.

Comments

0

Try using $Answer->dateCreated=date('Y-m-d');

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.