Daniel Wilson
asked on
PHP 5.2 -- Today's date - 7 days
How do I say:
$StartDate = Today's Date - 7 Days
in PHP 5.2?
I've seen stuff where the date is decomposed into month, day, year, subtracted and re-assembled. But that looks like August 5th - 7 days would come out to August -2nd ... which isn't really valid.
I was trying the DateTime::sub routine, but then found that my host is running 5.2, not 5.3.
I know this is a common need ... how is it done?
Thanks!
$StartDate = Today's Date - 7 Days
in PHP 5.2?
I've seen stuff where the date is decomposed into month, day, year, subtracted and re-assembled. But that looks like August 5th - 7 days would come out to August -2nd ... which isn't really valid.
I was trying the DateTime::sub routine, but then found that my host is running 5.2, not 5.3.
I know this is a common need ... how is it done?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ah - sorry. My laptop keyboard at home sometimes repeats characters that I type.
angelll's suggestion technically works. It simply returned a unix timestamp. The strtotime() function takes a formatted date or English description of a date and changes it into a timestamp:
$januaryFirst2009Timestamp = strtotime("01/01/2009");
print date("m/d/Y",$januaryFirst 2009Timest amp);
That code basically converts a date into a timestamp and then converts it back to the date again. Not really a useful piece of code, but it's a good illustration of converting back-and-forth between dates and timestamps.
Try date-formatting angelll's code:
echo date("m/d/Y",strtotime("-1 week"));
angelll's suggestion technically works. It simply returned a unix timestamp. The strtotime() function takes a formatted date or English description of a date and changes it into a timestamp:
$januaryFirst2009Timestamp
print date("m/d/Y",$januaryFirst
That code basically converts a date into a timestamp and then converts it back to the date again. Not really a useful piece of code, but it's a good illustration of converting back-and-forth between dates and timestamps.
Try date-formatting angelll's code:
echo date("m/d/Y",strtotime("-1
ASKER
07/14/2009
angelIII, yours gives me something funny ... but thanks for the shot at it!
1247582822