|
Posted by Andy Jeffries on 12/17/88 11:52
On Sun, 09 Jul 2006 07:50:41 -0700, Chung Leong 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.
>
> In one line:
I was trying to keep it simple... :-)
> $date_one_year_ago = strtotime("{$_POST['date']} -1 year",
> $date_user_entered);
What's the $date_user_entered for in your version (which will be null
unless assigned) ;-)
Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos
Navigation:
[Reply to this message]
|