Solved

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

Posted on 2006-07-23
5
1,403 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:rhinez0rz
5 Comments
 
LVL 10

Expert Comment

by:Khanh Doan
ID: 17165516
<?php
$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;
      }

      $minutes++;
}
$newdate = $rest . $minutes . $seconds;
echo $newdate;
?>

Goodluck.
Bonmat86.
0
 
LVL 29

Accepted Solution

by:
TeRReF earned 500 total points
ID: 17165892
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);
0
 
LVL 2

Expert Comment

by:arun80_inin
ID: 17168165
do you want to add 10 days to the current date
0
 

Author Comment

by:rhinez0rz
ID: 17170679
Thanks TeRReF, I think my question was a little vague, but you answered it perfectly. Fantastic!
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 17170685
You're welcome!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question