note 97821 added to function.gregoriantojd
| From: | brian at slaapkop dot net | Date: | Mon, 10 May 2010 14:53:03 +0000 |
| Subject: | note 97821 added to function.gregoriantojd | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169124@lists.php.net to get a copy of this message | ||
Some people might find it useful to use a function that takes in dates formatted by ISO8601
standards (yyyy-mm-dd):
<?php function daysBetweenDate($from, $till) {
/*
*This function will calculate the difference between two given dates.
*
*Please input time by ISO 8601 standards (yyyy-mm-dd).
*i.e: daysBetweenDate('2009-01-01', '2010-01-01');
*This will return 365.
*
*Author: brian [at] slaapkop [dot] net
*May 5th 2010
*/
if($till < $from) {
trigger_error("The date till is before the date from", E_USER_NOTICE);
}
//Explode date since gregoriantojd() requires mm, dd, yyyy input;
$from = explode('-', $from);
$till = explode('-', $till);
//Calculate date to Julian Day Count with freshly created array $from.
$from = gregoriantojd($from[1], $from[2], $from[0])."<br />";
//Calculate date to Julian Day Count with freshly created array $till.
$till = gregoriantojd($till[1], $till[2], $till[0])."<br />";
//Substract the days $till (largest number) from $from (smallest number) to get the amount of days
$days = ($till - $from);
//Return the number of days.
return $days;
//Isn't it sad how my comments use more lines than the actual code?
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 87.213.108.77
----
Manual Page -- http://www.php.net/manual/en/function.gregoriantojd.php
Edit -- https://master.php.net/note/edit/97821
Del: integrated -- https://master.php.net/note/delete/97821/integrated
Del: useless -- https://master.php.net/note/delete/97821/useless
Del: bad code -- https://master.php.net/note/delete/97821/bad+code
Del: spam -- https://master.php.net/note/delete/97821/spam
Del: non-english -- https://master.php.net/note/delete/97821/non-english
Del: in docs -- https://master.php.net/note/delete/97821/in+docs
Del: other reasons-- https://master.php.net/note/delete/97821
Reject -- https://master.php.net/note/reject/97821
Search -- https://master.php.net/manage/user-notes.php