Jump to content

Get date and pass it into URL


jarvis

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/208427-get-date-and-pass-it-into-url/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

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