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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.