Jump to content

datetime manipulation


Link

Recommended Posts

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);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.