note 34274 rejected from function.date by pollita
| From: | pollita@php.net | Date: | Sat, 26 Jul 2003 16:56:25 +0000 |
| Subject: | note 34274 rejected from function.date by pollita | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-52711@lists.php.net to get a copy of this message | ||
Note Submitter: daniel@daniel-wiedemann.de
----
I don't know if it helps someone but I wrote a lil function that converts the mySQL
"datetime" fieldtype into seconds.
I wanted to compare two dates(inclusiv time). For sure there exists a better way to, but I was too
decayed to look for it.
(sorry for my bad english, I'm from germany)
$datetime="2003-07-20 23:54:57" //somethin like that
function datetime2sec($datetime){
$years=$datetime['0'].$datetime['1']
.$datetime['2'].$datetime['3']*31536000;
$months=$datetime['5'].$datetime['6']*2678400;
$days=$datetime['8'].$datetime['9']*86400;
$hours=$datetime['11'].$datetime['12']*3600;
$minutes=$datetime['14'].$datetime['15']*60;
$seconds=$datetime['17'].$datetime['18'];
$insec=$years+$months+$days+$hours+$minutes+$seconds;
return $insec;
}
echo datetime2sec($datetime); //returns 20113572917