Incorrect datetime value: '20060723173061' for column 'upgrade_date' at row 1

I get the following error whenever I UPDATE a column with now()+10:

Incorrect datetime value: '20060723173061' for column 'upgrade_date' at row 1

I believe the reason is that the last two digits '61' cannot exist in date format, this would be the same as saying 61 seconds, when there can only be 60 seconds in a minute. How do I create an update function that will round to the next minute in this instance so I don't get this error?

Many thanks
Who is Participating?
TeRReFConnect With a Mentor Commented:
You are mixing up two types. datetime and timestamp. You must convert the timestamp (time()+10) to datetime first before you make the insert.

$newdate = date("YmdHis", time()+10);
Khanh DoanSenior DeveloperCommented:
$date = '20060723173061';
$seconds = substr($date, 12, 2);
$minutes = substr($date, 10, 2);
$rest = substr($date, 0, 10);

if ($seconds >= '60')
      $seconds = $seconds - 60;
      if ($seconds < 10)
            $seconds = '0' . $seconds;

$newdate = $rest . $minutes . $seconds;
echo $newdate;

do you want to add 10 days to the current date
rhinez0rzAuthor Commented:
Thanks TeRReF, I think my question was a little vague, but you answered it perfectly. Fantastic!
You're welcome!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.