Jump to content

date from database + 365 days?


merylvingien

Recommended Posts

Hi fellas, this is really kicking my arse and i know its so simple!

 

I retrieve a date from the database, done!

I am manipulating it to display as i want, done!

How the hell do i add 365 days to this date?

 

$date= ($row['date']);
$subscription = strtotime($date);
echo
"<p>Subscription renewal date: ". date('l jS F Y', $subscription) . "</p>";

Link to comment
https://forums.phpfreaks.com/topic/216821-date-from-database-365-days/
Share on other sites

Adding 1 year to a php date object is sometimes useful to solve some programming problem. You can add 365 days to year, but the php provides method to add 1 year easily. The code given below will show how you can add 1 year in php program.

 

<?php

 

 

//Example to add 1 year to a date object

 

$currentDate = date("Y-m-d");// current date

 

//Display the current date

echo "Current Date: ".$currentDate."<br>";

 

//Add one year to current date

$dateOneYearAdded = strtotime(date("Y-m-d", strtotime($currentDate)) . " +1 year");

echo "Date After adding one year: ".date('l dS \o\f F Y', $dateOneYearAdded)."<br>";

 

?>

 

Output of the program:

 

Current Date: 2009-08-29

Date After adding one year: Sunday 29th of August 2010

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.