jarvis Posted July 21, 2010 Share Posted July 21, 2010 Hi All, I've got the following URL: http://www.mydomain.com?ec3_after=2010-07-21&ec3_before=2010-07-22 This then returns a list of results after todays date but before 7 days time. Unfortunately, this is hard coded and I'd like to make it dynamic. How the hell can I get todays date and pass it into the above? Was thinking something like: $start_today = date('Y m d'); $end_date = ''; http://www.mydomain.com?ec3_after=<?php echo $start_date; ?>&ec3_before=<?php echo $end_date; ?>& However, I can't work out how to add the - in the date. I also can't work out how to add 7 days, adding 7 wont work as you need to know which month as to which date the month ends on. Any help is much appreciated! Many thanks in advanced! Quote Link to comment https://forums.phpfreaks.com/topic/208427-get-date-and-pass-it-into-url/ Share on other sites More sharing options...
AbraCadaver Posted July 21, 2010 Share Posted July 21, 2010 $start_today = date('Y-m-d'); //add the - here $end_date = date('Y-m-d', strtotime('+7 days')); http://www.mydomain.com?ec3_after=<?php echo $start_date; ?>&ec3_before=<?php echo $end_date; ?> Quote Link to comment https://forums.phpfreaks.com/topic/208427-get-date-and-pass-it-into-url/#findComment-1089156 Share on other sites More sharing options...
jarvis Posted July 21, 2010 Author Share Posted July 21, 2010 Thanks Shawn, How does this work strtotime('+7 days')); does it know to check whether you're inside 30 or 31 days, i.e. what happens if you're on the 28th of the month? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/208427-get-date-and-pass-it-into-url/#findComment-1089161 Share on other sites More sharing options...
AbraCadaver Posted July 21, 2010 Share Posted July 21, 2010 Thanks Shawn, How does this work strtotime('+7 days')); does it know to check whether you're inside 30 or 31 days, i.e. what happens if you're on the 28th of the month? Cheers PHP date and time functions are well aware of the calendar, how many days are in each month, when it is leap year and takes into account daylight savings time and calculates based on time zones. Do some tests and you'll see it works great: echo date('Y-m-d', strtotime('2/25/2010 +7 days')); echo date('Y-m-d', strtotime('2/25/2008 +7 days')); // leap year Quote Link to comment https://forums.phpfreaks.com/topic/208427-get-date-and-pass-it-into-url/#findComment-1089167 Share on other sites More sharing options...
jarvis Posted July 21, 2010 Author Share Posted July 21, 2010 Thank you, that's great! Dont like to just use these things. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/208427-get-date-and-pass-it-into-url/#findComment-1089169 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.