Jaeger wrote: » I had initially considered writing a basic function to convert dd/mm/yyyy hh:mm:ss into a string format of yyyy/mm/dd hh:mm:ss, and then storing the returned value in the SQL table, before I gathered I should be able to do that using existing functionality.
Jaeger wrote: » PS. Do I need to store the date and time in separate fields?
$inputdate = "08/07/2009 07:32:30"; $outputdate = date("d-m-Y H:i:s", strtotime($inputdate)); echo $outputdate; // produces "07-08-2009 07:32:30"
SELECT UNIX_TIMESTAMP(columnwithdatetime) as unixdatetime from tablename
function timeDifference($oldtime) { $time = time(); $elapsed = $time - $oldtime; $years = date('Y', $elapsed) - 1970; // Calculate the year subtracting the beginning year 1970 $months = date('m', $elapsed); $days = date('d', $elapsed); $hours = date('H', $elapsed); $min = date('i', $elapsed); // return array('years'=>$years, 'months'=>$months, 'days'=>$days, 'hours'=>$hours, 'minutes'=> $min); // Return values as an array } // $arrayname[starttime] is populated by SELECT UNIX_TIMESTAMP(StartTime) as StartTime from table; $starttime = $arrayname[starttime]; $friendlystarttime = date("d/m/Y H:i:s", $starttime); $friendlycurrenttime = date("d/m/Y H:i:s", time()); echo "Time held in table: " .$starttime ." <b>(".$friendlystarttime.")</b><br />"; echo "Current date/time (UNIX): " . time() ." <b>(".$friendlycurrenttime.")</b><br />"; $timediff = timeDifference($starttime); print_r($timediff);
<?php function compare_dates($date1, $date2){ $blocks = array( array('name'=>'year','amount' => 60*60*24*365), array('name'=>'month','amount' => 60*60*24*31), array('name'=>'week','amount' => 60*60*24*7), array('name'=>'day','amount' => 60*60*24), array('name'=>'hour','amount' => 60*60), array('name'=>'minute','amount' => 60), array('name'=>'second','amount' => 1) ); $diff = abs($date1-$date2); $levels = 2; $current_level = 1; $result = array(); foreach($blocks as $block){ if ($current_level > $levels) {break;} if ($diff/$block['amount'] >= 1){ $amount = floor($diff/$block['amount']); if ($amount>1) {$plural='s';} else {$plural='';} if ($amount <10) {$prefix='0';} else {$prefix='';} $result[] = $prefix . $amount.' '.$block['name'].$plural; $diff -= $amount*$block['amount']; } } return implode(' ',$result); } ?>