merylvingien Posted October 25, 2010 Share Posted October 25, 2010 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 More sharing options...
Rifts Posted October 25, 2010 Share Posted October 25, 2010 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 https://forums.phpfreaks.com/topic/216821-date-from-database-365-days/#findComment-1126402 Share on other sites More sharing options...
merylvingien Posted October 25, 2010 Author Share Posted October 25, 2010 Thanking you! Link to comment https://forums.phpfreaks.com/topic/216821-date-from-database-365-days/#findComment-1126404 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.