Re: getting a date 25 years back
| From: | Richard Lynch | Date: | Tue, 14 Dec 2004 22:28:17 +0000 |
| Subject: | Re: getting a date 25 years back | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-204352@lists.php.net to get a copy of this message | ||
Merlin wrote:
> I am trying to create a date which is 25 years back from today. The
> purpose of
> this is to be able to query a mysql database "date" field for columns
> smaller
> than this date.
>
> I tried this:
> $years = 25;
//> $start_from = date("Y-m-d",strtotime("- ".$years." year"));
>
> Somehow it always ads the years instead of subtracting.
>
> Has anybody an idea on how to do that?
You can do this in all MySQL:
select ... where date_field <= sub_date(now(), interval 25 years)
Or you could try:
$back_then = mktime(0, 0, 0, date('m'), date('d'), date('Y') - 25);
$start_from = date("Y-m-d", $back_then);
--
Like Music?
http://l-i-e.com/artists.htm