Sydcomebak Posted July 30, 2008 Share Posted July 30, 2008 How do I represent the date() function and increment by 7 days? 1 month? 1 year? $dateRange = sprintf(', CompanyStart = "%s", CompanyEnd = "%s"', date("Y-m-d"), date("Y-m-d")+7); Quote Link to comment https://forums.phpfreaks.com/topic/117276-solved-date-increment-by-7-days/ Share on other sites More sharing options...
.josh Posted July 30, 2008 Share Posted July 30, 2008 From the manual: $plussevendays = mktime(0, 0, 0, date("m"), date("d")+7, date("Y")); $plusonemonth = mktime(0, 0, 0, date("m")+1, date("d"), date("Y")); $plussoneyear = mktime(0, 0, 0, date("m"), date("d"), date("Y")+1); Quote Link to comment https://forums.phpfreaks.com/topic/117276-solved-date-increment-by-7-days/#findComment-603258 Share on other sites More sharing options...
Zane Posted July 30, 2008 Share Posted July 30, 2008 date("+7 days +1 month +1 year"); RTM. http://www.php.net/date oops...I'm sorry date("Y-m-d", strtotime("+7 days 1 month 1 year")); Quote Link to comment https://forums.phpfreaks.com/topic/117276-solved-date-increment-by-7-days/#findComment-603259 Share on other sites More sharing options...
ratcateme Posted July 30, 2008 Share Posted July 30, 2008 use strtotime with date: date("Y-m-d", strtotime("+1 day")); date("Y-m-d", strtotime("+1 month")); date("Y-m-d", strtotime("+1 year")); Scott. Quote Link to comment https://forums.phpfreaks.com/topic/117276-solved-date-increment-by-7-days/#findComment-603260 Share on other sites More sharing options...
derekmcd Posted July 30, 2008 Share Posted July 30, 2008 first of all you need to get a current timestamp (which is in seconds) and add the number of seconds to the current timestamp that are in 7 days <?php $nowtime = time(); $startDate = date("Y-m-d", $nowtime); $endDate = date("Y-m-d", ($nowtime + (60 * 60 * 24 * 7)); $dateRange = sprinttf(', CompanyStart = "%s", CompanyEnd = "%s"', $startDate, $endDate); ?> That should make your end date 1 week (7 Days) more than the current time. Quote Link to comment https://forums.phpfreaks.com/topic/117276-solved-date-increment-by-7-days/#findComment-603262 Share on other sites More sharing options...
Zergman Posted July 30, 2008 Share Posted July 30, 2008 This works great for using dates, but what about time? My hosts server is 2 hours ahead of my time zone. I want to be able to use my PC's time to insert into my form. I checked both date() and time() but can't find a way to accomplish this. Quote Link to comment https://forums.phpfreaks.com/topic/117276-solved-date-increment-by-7-days/#findComment-603406 Share on other sites More sharing options...
Zergman Posted July 30, 2008 Share Posted July 30, 2008 nvm, figured it out $myplace = date("h:i a", time() - 7200); Quote Link to comment https://forums.phpfreaks.com/topic/117276-solved-date-increment-by-7-days/#findComment-603410 Share on other sites More sharing options...
Sydcomebak Posted July 30, 2008 Author Share Posted July 30, 2008 Thanks everybody! It worked perfectly! I'm new to PHP, so having you guys around is really amazing. -Dave Quote Link to comment https://forums.phpfreaks.com/topic/117276-solved-date-increment-by-7-days/#findComment-603561 Share on other sites More sharing options...
Zergman Posted July 31, 2008 Share Posted July 31, 2008 Something weird happened today. Had this in my page $date = date ('Y-m-d'); $backmonth = date("Y-m-d", strtotime("-1 month")); Was working yesterday, now these variables give me this 2008-07-31 2008-07-01 Im guessing its my server thats causing this .... not sure where they are located actually but can anybody explain whats going on? Quote Link to comment https://forums.phpfreaks.com/topic/117276-solved-date-increment-by-7-days/#findComment-604301 Share on other sites More sharing options...
Zergman Posted July 31, 2008 Share Posted July 31, 2008 Tried doing this $date = date ('Y-m-d'); $backmonth = date("Y-m-d", strtotime("-2 month")); Gives me this 2008-07-31 2008-05-31 This isn't making sense. Why does -1 month return 30 days which lies within the same current month, but -2 works fine? I know my server time is 2hrs ahead of me btw Quote Link to comment https://forums.phpfreaks.com/topic/117276-solved-date-increment-by-7-days/#findComment-604303 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.