Mega Code Archive

 
Categories / Php / Date Time
 

Convert dates in YYYY-MM-DD (i.e. mysql format) into PHP3 timestamps

<? function GetTimeStamp($MySqlDate) { /* Take a date in yyyy-mm-dd format and return it to the user in a PHP timestamp Robin 06/10/1999 */ $date_array = explode("-",$MySqlDate); // split the array $var_year = $date_array[0]; $var_month = $date_array[1]; $var_day = $date_array[2]; $var_timestamp = mktime(0,0,0,$var_month,$var_day,$var_year); return($var_timestamp); // return it to the user } function GetDayDiff($ts_1, $ts_2) { /* This will return the difference in days between two PHP timestamps Robin 06/10/1999 */ // calculate which is the larger so we never get negative answers if ($ts_1 > $ts_2) { // $ts_1 is larger $var_days = ($ts_1 - $ts_2) / 86400; /// 60 / 60 / 24; } elseif ($ts_1 < $ts_2) { // $ts_1 is smaller $var_days = ($ts_2 - $ts_1) / 86400; /// 60 / 60 / 24; } else { // they must be equal $var_days = 0; } return($var_days); //return the value } ?>