|
Posted by Chung Leong on 10/07/41 11:52
Andy Jeffries wrote:
> On Sun, 09 Jul 2006 02:05:51 -0700, phforum wrote:
> > If user input the date is 2006-07-01. How to convert it to last year
> > 2005-07-01?
>
> The simplest way is as follows:
>
> $date_user_entered = strtotime($_POST["date"]);
> $date_one_year_ago = strtotime("-1 year", $date_user_entered);
>
> This also works perfectly with leap years which some other solutions may
> not.
>
> Cheers,
In one line:
$date_one_year_ago = strtotime("{$_POST['date']} -1 year",
$date_user_entered);
Navigation:
[Reply to this message]
|