PHP: Date before X days
Question by CSchaf | Last update on 2020-10-20 | Created on 2016-11-01
Is there any possibility to calculate with dates in PHP?
I would like to subtract some days from the current date, for example to determine the date of yesterday, the date 10 days ago or the date 100 days ago. Can someone help me?
Related Topics
PHP: Current Date and Time
Tutorial | 0 Comments
MySQL: Write current Date or Time into Column
Tutorial | 0 Comments
PHP: Determine Week Number
Tutorial | 0 Comments
JavaScript: Get current Date and Time
Tutorial | 1 Comment
VirtualBox: Change Date and Time
Tutorial | 10 Comments
HTML Form: Redirection depending on Radiobutton or Checkbox State
Tutorial | 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 do that quite easy using the PHP function strtotime(). You can pass a date in text form to this function and you get a timestamp back.
You can even work with time constants such as day, week, month or year. Here are some examples for you:
This outputs the date of yesterday, that is the date one day back in past.
This outputs the date before one week, that is the date before seven days.
Using this code, you get the date ten days ago.
And using this code, you get the date one hundred days ago.
2016-11-01 at 23:52