Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with finding the days between two unix timestamps
    primarykey
    data
    text
    <p>I know there a lot of questions and answers of this already, but unfortunately I think my situation may be unique? For some reason, the time-change seems to be making the day calculate as one day less than it should be calculating.</p> <p>Here is my PHP that I was using and it was working great, until it started to overlap a start and end date that was BEFORE daylight savings, and AFTER daylight savings, respectively (FYI, this is a recent issue, since daylight savings time starts this weekend!):</p> <pre><code>//$lastDate and $firstDate are 2 unix timestamps with valid month, day, and year values. //The times are irrelevant at this point, they are only meant to represent a day. //I start by making sure these have the same time values. $lastDate = mktime(23, 59, 59, date("m", $lastDate), date("j", $lastDate), date("Y", $lastDate)); $firstDate = mktime(23, 59, 59, date("m", $firstDate), date("j", $firstDate), date("Y", $firstDate)); //Then calculate the total number of days in between. $totalDays = abs(floor(($firstDate - $lastDate)/(60*60*24))); </code></pre> <p>So again, to be clear, the above works if i'm not overlapping the daylight savings time change...</p> <p>For reference:</p> <p><a href="https://stackoverflow.com/questions/2736784/how-to-find-the-dates-between-two-specified-date">How to find the dates between two specified date?</a></p> <p><a href="https://stackoverflow.com/questions/9035589/actual-days-between-two-unix-timestamps-in-php">Actual days between two unix timestamps in PHP</a></p> <p><a href="https://stackoverflow.com/questions/4079814/finding-days-between-2-unix-timestamps-in-php">Finding days between 2 unix timestamps in php</a></p> <p>And, I'm still on PHP 5.2 right now.</p> <p><strong>EDIT/UPDATE:</strong><br> I've found the following on this links: </p> <p><a href="https://stackoverflow.com/questions/2736784/how-to-find-the-dates-between-two-specified-date">How to find the dates between two specified date?</a></p> <p>and</p> <p><a href="https://stackoverflow.com/questions/3751712/how-to-calculate-the-the-interval-between-2-unix-timestamps-in-php-without-divid">How to calculate the the interval between 2 unix timestamps in php WITHOUT dividing by 86400 (60*60*24)</a></p> <pre><code>//$lastDate and $firstDate are 2 unix timestamps with valid month, day, and year values. //The times are irrelevant at this point, they are only meant to represent a day. //I start by making sure these have the same time values. $lastDate = mktime(10, 00, 00, date("m", $lastDate), date("j", $lastDate), date("Y", $lastDate)); $firstDate = mktime(10, 00, 00, date("m", $firstDate), date("j", $firstDate), date("Y", $firstDate)); //Then calculate the total number of days in between. $totalDays = floor($firstDate / 86400) - floor($lastDate/ 86400); </code></pre> <p>And it seems to work right now for the crossover of DST. Anyone see any issues with this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload