How can the "last week" parameter in strtotime be utilized in PHP date calculations?
When using the "last week" parameter in strtotime in PHP date calculations, you can retrieve the timestamp for the same day of the week from the previous week. This is useful for comparing data from the current week to the previous week or for generating reports based on weekly data.
// Get the timestamp for the same day of the week from last week
$lastWeekTimestamp = strtotime('last week', strtotime('today'));
// Format the timestamp as a date
$lastWeekDate = date('Y-m-d', $lastWeekTimestamp);
echo "Last week's date: " . $lastWeekDate;
Keywords
Related Questions
- In what scenarios should PHP developers consider using anchor tags to automatically redirect users to a specific data record after saving changes in PHP scripts?
- How can PHP developers ensure cross-platform compatibility when using functions like dirname() that handle directory paths?
- How can the warning messages related to array_keys() and max() be resolved in PHP 7.1?