PHP Classes

error on unixstamp

Recommend this page to a friend!

      SimpleXLSX  >  All threads  >  error on unixstamp  >  (Un) Subscribe thread alerts  
Subject:error on unixstamp
Summary:Wrong number subtraction
Messages:5
Author:Yuri Nunes
Date:2013-12-10 02:13:00
Update:2014-01-16 20:01:58
 

 


  1. error on unixstamp   Reply   Report abuse  
Picture of Yuri Nunes Yuri Nunes - 2013-12-10 02:13:00
In unixstamp function, the number 25569 is wrong. Making the calculation of the period between 1900 and 1970 in Excel the result will be that number, but the count starts from number one, then it is necessary to subtract this one. The correct value is 25568.

Sorry my english

  2. Re: error on unixstamp   Reply   Report abuse  
Picture of Sergey Shuchkin Sergey Shuchkin - 2013-12-10 05:21:40 - In reply to message 1 from Yuri Nunes
give me your formula

  3. Re: error on unixstamp   Reply   Report abuse  
Picture of Yuri Nunes Yuri Nunes - 2013-12-10 13:26:16 - In reply to message 2 from Sergey Shuchkin

function unixstamp( $excelDateTime ) {
$d = floor( $excelDateTime ); // seconds since 1900
$t = $excelDateTime - $d;
return ($d > 0) ? ( $d - 25568 ) * 86400 + $t * 86400 : $t * 86400;
}

  4. Re: error on unixstamp   Reply   Report abuse  
Picture of Sergey Shuchkin Sergey Shuchkin - 2013-12-10 19:13:18 - In reply to message 3 from Yuri Nunes
Spasibo tebe Yuri

  5. Re: error on unixstamp   Reply   Report abuse  
Picture of Yuri Nunes Yuri Nunes - 2014-01-16 20:01:58 - In reply to message 4 from Sergey Shuchkin
Hi friend, I did some testing and found another problem, but now, in my correction. I do not know if you've tested my function. The problem happens because of DST(Daylight Saving Time). I'm in Brazil and at the moment, we are in the summer time and this makes the function of converting dates do not work properly. So to fix this, I set the timezone to UTC.

function unixstamp( $excelDateTime ) {
date_default_timezone_set('UTC');
$d = floor( $excelDateTime ); // seconds since 1900
$t = $excelDateTime - $d;
return ($d > 0) ? ( $d - 25569 ) * 86400 + $t * 86400 : $t * 86400;
}

I hope to help me and excuse my bad english.