You are here: Re: How to convert current date to last year date? « PHP Programming Language « IT news, forums, messages
Re: How to convert current date to last year date?

Posted by Janwillem Borleffs on 12/17/61 11:52

phforum wrote:
> If user input the date is 2006-07-01. How to convert it to last year
> 2005-07-01?
>

If this is the fixed pattern, the simplest thing you can do is something as
follows:

$date = "2006-07-01";
list($y, $m, $d) = explode('-', $date);
$newdate = (--$y) . "-$m-$d";

However, this will cause problems when the date is the 29th of February in a
leap year, while the previous is a regular year. To fix this, you can apply
the strtotime() function:

$date = "2004-02-29";
$ts = strtotime("last year", strtotime($date));
$newdate = date('Y-m-d', $ts);


HTH;
JW

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация