Cronospulse Posted April 27, 2009 Share Posted April 27, 2009 mysql server version = 5.1.32 Im trying to add 1 hour to a timestamp with strotime The code im using to do this gives a random problem wich i cant seem to solve. the following code: //database time echo $rows['time']."<br>"; // +1 hour echo $time = date("Y-m-d H:i:s", strtotime( "$rows[time] +1 hour" ))."<br><br>"; gives these values: 2009-04-27 16:03:47 2009-04-27 17:03:47 2009-04-27 16:04:53 2009-04-27 17:04:53 2009-04-27 16:04:59 1970-01-01 01:00:00 2009-04-27 16:05:06 2009-04-27 17:05:06 only the on date with 1970 makes no sence its exactly the same in as the other date's but it stil gives this problem. The time is made as timestamp in mysql. If some one can help me with this i would realy apreciate it im stuck on it. Link to comment https://forums.phpfreaks.com/topic/155843-mysql-timestamp-php-strtotime-problem/ Share on other sites More sharing options...
Mchl Posted April 27, 2009 Share Posted April 27, 2009 Can't reproduce it... 1970-01-01... indiates that strtotime failed for whatever reason, but you're echoing the value before, and it seems to be fine What if you try echo $time = date("Y-m-d H:i:s", strtotime( "$rows[time]" )+3600)."<br><br>"; It's more PHP problem than a MySQL one. Link to comment https://forums.phpfreaks.com/topic/155843-mysql-timestamp-php-strtotime-problem/#findComment-820286 Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2009 Share Posted April 27, 2009 Use var_dump() on the starting value to show the length as well. I'm going to guess it has some extra non-printing (non-echoing in this case) characters. What is your column data type in the database? Link to comment https://forums.phpfreaks.com/topic/155843-mysql-timestamp-php-strtotime-problem/#findComment-820294 Share on other sites More sharing options...
Cronospulse Posted April 27, 2009 Author Share Posted April 27, 2009 Thanks for the quick awnser the +3600 solves the problem. But I'm stil a bit quirius about what couses a problem like this. Again thanks for the awnser. Link to comment https://forums.phpfreaks.com/topic/155843-mysql-timestamp-php-strtotime-problem/#findComment-820296 Share on other sites More sharing options...
Cronospulse Posted April 27, 2009 Author Share Posted April 27, 2009 the row i use in the database looks like this `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP Link to comment https://forums.phpfreaks.com/topic/155843-mysql-timestamp-php-strtotime-problem/#findComment-820298 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.