superdan_35 Posted April 20, 2009 Share Posted April 20, 2009 Hi all. I currently have a database that stores various details relating to each day in a business. I want to be able to take the last date something was entered and display a form for the user to enter the details for the next seven days. I have selected the most recent value from the database, which is of type date("Y-m-d"), but now I cannot work out how to increase it. I have tried to add 1 but that increases it by 1 year, I have tried to increase it by seconds but as it's not a timestamp that doesn't work. I have searched around for a while and had no luck. So I have considered splitting up the date, increasing the day value and putting it back together, but before I try that does anyone have any suggestions? Thanks very much, Dan Link to comment https://forums.phpfreaks.com/topic/154885-increase-date-value/ Share on other sites More sharing options...
soak Posted April 20, 2009 Share Posted April 20, 2009 $unixTime = strtotime($date); Gives you the time in seconds since the unix epoch. As it's in seconds you can add 60 to it to add a minute, add (60 * 60) to add an hour etc etc. It's common when you're doing this to split it down like that so it's easy to read for the next person looking at your code. So to add a day: $unixTime = $unixTime + (60 * 60 * 24); There are other ways but this is easy and reliable. To get it back to Y-m-d just do: echo date('Y-m-d', $unixTime); Link to comment https://forums.phpfreaks.com/topic/154885-increase-date-value/#findComment-814654 Share on other sites More sharing options...
kenrbnsn Posted April 20, 2009 Share Posted April 20, 2009 You can use a for loop with date and strtotime <?php $start_date = '2009-04-30'; $st = strtotime($start_date); $end = strtotime('+7 days',$st); for ($i=$st;$i<$end;$i += 86400) { // 86400 seconds in a day echo date('l, F jS, Y',$i) . '<br>'; } ?> Ken Link to comment https://forums.phpfreaks.com/topic/154885-increase-date-value/#findComment-814660 Share on other sites More sharing options...
superdan_35 Posted April 22, 2009 Author Share Posted April 22, 2009 Thanks for you help. It now works perfectly! Dan Link to comment https://forums.phpfreaks.com/topic/154885-increase-date-value/#findComment-816366 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.