1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
billsblogpage

Friday, September 18, 2009

date diff in php

Friday, September 18, 2009
it is a common task to determine the number of days from one given date to another. and with php there are a number of ways to tackle this. one of the easiest i have found is to use the gregoriantojd() function.

the gregoriantojd() function requires three parameters: month, day, year. it will return you an integer containing the julian day. once you have converted each date, it is then a simple matter of subtracting one from the other.
this will find the number of days until january 1, 2010:

$today = date("Y-m-j");
$days = datediff($today, '2010-01-01');
echo "days until january 1, 2010 is : " . $days;

now call the datediff function which calculates the number of days:

function dateDiff($startDate, $endDate)
{
    $date1=explode('-', $startDate);
    $date2=explode('-', $endDate);
    $startDate=gregoriantojd($date1[1], $date1[2], $date1[0]);
    $endDate=gregoriantojd($date2[1], $date2[2], $date2[0]);
    return $endDate - $startDate;
}

1 comment:

  1. You’ll have 3 weeks to satisfy their playthrough and money out a maximum of 30x your original deposit. If you propose to go big or go home, Red Dog 1xbet places serious money on the table. They’re all the time adding more games to their betting library, so you’ll find something new to discover each time you log in. Red Dog prioritizes quality over quantity with 120+ cutting-edge free slots reels from Realtime Gaming . Another thrilling slot experience that includes the player-favorite Fu Babies™.

    ReplyDelete