php - the most accurate way to calucate date periods using the date object -
i working on access site, paying members 3 months access period site. issue hence how calculate exact 3 month date period.
i.e, months 28 days, others 31 days; normal years 365 lunar year 354 days.
i thinking of converting date unix timestamps , calculating 3 months in seconds. not sure whether efficient , accurate way it.
below proposal , appreciate advice on it;
timestamp when clocks starts
$unixtimestampnow = new \datetime("now"))->format('u')
calculating 3 months date:
$numberdaysinmonth = 30.41 = 365/ 12 //number of days in months $numbersecondsinday = 86400; //number seconds in day $secondsin3months = ($numberdaysinmonth * $numbersecondsinday) * 3 //number seconds in 3 months new \datetime("$secondsin3months"); //convert date object
like said, best came with, suspect not accurate.
would appropriate advice
as said in comment, utilize datetime object's add()
method dateinterval
$d = new \datetime("now"); $d->add(new \dateinterval('p3m')); echo $d->format('y-m-d h:i:s');
php datetime
No comments:
Post a Comment