Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding one year to a date

Status
Not open for further replies.

McKaulick

Programmer
Oct 24, 2002
35
AR
Hello everyone,

I want to add one year to a date with this format: "2007-12-13" so I can say if today's date is smaller than the one on the database + 1 year.

Can someone has a way to add it.

When I print $todayDate+1; the result = just the year "2008" but not "2008-12-13".

PHP has lots of details but sometimes examples are too complicated for nothing and my brain is tired now.

Thanks anyone.

 
Code:
$date = "2007-02-21";
$unixdate = strtotime($date);
$ny_unix = strtotime('+1 year', $unixdate);
$ny_date = date ('Y-m-d', $ny_unix);
echo $ny_date;
 
If your dates are all formatted as you have show, it's not necessary to use PHP's date functions. So I wouldn't. This script:

Code:
<?php
$year = '2007-02-21';
$year_array = split ('-', $year);
$year_array[0]++;
$new_year = implode ('-', $year_array);
echo $new_year;
?>

outputs:

[tt]2008-02-21[/tt]



Want the best answers? Ask the best questions! TANSTAAFL!
 
and on rereading the original post, you can actually do what you are looking for within mysql itself, and avoid using any php. a post in the mysql forum would doubtless provide you with a quick answer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top