How to check in php if today is a 'due date'
I'm writing a program in php where a user gets credits monthly based in their registration date.
I'm writing a cron job that would be run daily.
I need to determinate if a date if a due date
In others words;
If a reg开发者_开发问答istered in date 2010-02-10
and today is 2011-07-10
I should get credited.
So the question is how can I deteminate reliably in php that two dates are separated by a whole month.
Or alternatively how can I get the next due date
. For example today is 2011-07-18
so the next due date
would be 2011-08-10
If you convert your date (fetched from the database, most likely) into a DateTime PHP object, you can use the DateTime class' methods to add exactly one month and compare that date with the current date.
As an example from the PHP documentation, this snippet adds 10 days to a given date.
<?php
$date = new DateTime('2000-01-01');
$date->add(new DateInterval('P10D'));
echo $date->format('Y-m-d') . "\n";
精彩评论