PHP: Date 1 week ago
Question by WebHorn | Last update on 2023-11-23 | Created on 2016-10-30
I would like to determine the date exactly one week before today in a PHP script.
Unfortunately, it is not that easy that you can just subtract 7 days from the current date, because you also have to consider changes of months and years. Does someone have an idea?
Related Topics
PHP: Determine Week Number
Tutorial | 0 Comments
PHP: Current Date and Time
Tutorial | 0 Comments
MySQL: Write current Date or Time into Column
Tutorial | 0 Comments
PHP: Wrong Year for first Calendar Week
Question | 1 Answer
JavaScript: Get current Date and Time
Tutorial | 1 Comment
MySQL: Line Breaks in MySQL
Tip | 0 Comments
Change Date of File
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
You can just use the function strtotime() and pass "-7 days" or "-1 week" to go back seven days respectively one week into the past:
In this example, we are first storing the timestamp within the variable $t and then we are displaying the date in the format day.month.year using PHP's date() function.
When using "-1 week" instead of "-7 days" the result is the same.
Last update on 2023-11-23 | Created on 2016-10-31