Link Posted September 1, 2008 Share Posted September 1, 2008 Hello! I have a datetime string in the form "DD-MM-YYYY HH:MM:SS", and I was wondering if there is a function so that I can add x minutes to that datetime to make a new one. Anyone? Link to comment https://forums.phpfreaks.com/topic/122170-datetime-manipulation/ Share on other sites More sharing options...
Link Posted September 1, 2008 Author Share Posted September 1, 2008 Just kidding, the format is "YYYY-MM-DD HH:MM:SS"... it's datetime for a mysql database Link to comment https://forums.phpfreaks.com/topic/122170-datetime-manipulation/#findComment-630730 Share on other sites More sharing options...
spfoonnewb Posted September 1, 2008 Share Posted September 1, 2008 Theres probably a better way to do this with mysql, however I don't mysql dates often. I do know there is a select that will convert to unix time. <?php //YYYY-MM-DD HH:MM:SS - 2007-12-31 11:57:42 function convertDate($str, $array) { list($date, $time) = explode(' ', $str); list($year, $month, $day) = explode('-', $date); list($hour, $minute, $second) = explode(':', $time); $timestamp = mktime($hour + $array['hour'], $minute + $array['minute'], $second + $array['second'], $month + $array['month'], $day + $array['day'], $year + $array['year']); return $timestamp; } //How many of each to add - if any $setArray = array( "hour" => "", "minute" => "5", "second" => "", "month" => "", "day" => "", "year" => "" ); $startDate = "2007-12-31 11:57:42"; $unixStamp = convertDate($startDate, $setArray); echo date("Y-m-d g:i:s", $unixStamp); ?> Link to comment https://forums.phpfreaks.com/topic/122170-datetime-manipulation/#findComment-630734 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.