note 68112 deleted from ref.datetime by nlopess

From: Date: Fri, 08 Sep 2006 12:02:22 +0000
Subject: note 68112 deleted from ref.datetime by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-116899@lists.php.net to get a copy of this message
Note Submitter: flintjt at NOSPAMATALL dot hotmail dot com ---- Here are some functions that I put together to convert between Unix and Excel (windows) Dates: ############################### # convert_excel2unix function: # Converts excel date/time stamps to unix timestamp. ############################### function convert_excel2unix($excel_v) { $unix_v = (($excel_v - 25569) * 86400); $text_v = gmdate("m/d/Y H:i:s",$unix_v); $unix_v = strtotime($text_v); return $unix_v; }#End of function to convert excel2unix timestamp. ############################### ############################### # convert_unix2excel function: # Converts unix timestamps to excel date/time stamps. ############################### function convert_unix2excel($unix_v) { $excel_arr = array( excel_date_v => "", #numeric: excel style date stamp (no decimal number) excel_dt_v => "", #numeric: excel style date timestamp (Can include decimal) excel_time_v => "", #numeric: excel style timestamp (not a whole number) );#End of excel array. if($unix_v > 86400) { $tz_v = date("Z",$unix_v); #print "Z\t$tz_v\n"; $excel_arr[excel_dt_v] = (($unix_v + $tz_v)/86400) + 25569; #+ 15168 - $excel_arr[excel_date_v] = $excel_arr[excel_dt_v]; if(strstr($excel_arr[excel_dt_v],".")) { $excel_v_arr = explode(".", $excel_arr[excel_dt_v]); $excel_arr[excel_date_v] = $excel_v_arr[0]; $excel_arr[excel_time_v] = ".".$excel_v_arr[1]; }#End of if excel_dt_v contains a period. }#If its a date time stamp. else { $excel_arr[excel_time_v] = $unix_v / 86400; $excel_arr[excel_dt_v] = $excel_arr[excel_time_v]; }#Else its a timestamp only. return $excel_arr; }#End of function to convert excel2unix timestamp. ###############################

« previous php.notes (#116899) next »