Php date minus 1 year
I've got a date in this format: Show
How do I return the same date but 1 year earlier?
elitalon 9,0219 gold badges48 silver badges86 bronze badges asked Jan 2, 2010 at 1:43
2 You can use
The
answered Jan 2, 2010 at 1:45
0
Use strtotime() function:
answered Jan 2, 2010 at 1:45
AlexAlex 3,1002 gold badges21 silver badges22 bronze badges 1 Using the DateTime object...
Or using now for today
answered Sep 10, 2013 at 8:34
darrenwhdarrenwh 6305 silver badges4 bronze badges 1 an easiest way which i used and worked well
this worked perfect.. hope this will help someone else too.. :) answered Oct 26, 2016 at 6:58
saadksaadk 1,17512 silver badges17 bronze badges
answered Jan 2, 2010 at 1:57
NirmalNirmal 9,24110 gold badges54 silver badges80 bronze badges On my website, to check if registering people is 18 years old, I simply used the following :
After, only compare the the two dates. Hope it could help someone. answered Dec 5, 2018 at 8:09
MelomanMeloman 3,2343 gold badges39 silver badges44 bronze badges Although there are many acceptable answers in response to this question, I don't see any examples of the So, for reference, you can also use a
Which returns:
For more information about answered Jan 13, 2020 at 13:09
Oliver TappinOliver Tappin 2,4511 gold badge23 silver badges42 bronze badges You can use the following function to subtract 1 or any years from a date.
And looking at above examples you can also use the following
answered Aug 26, 2017 at 11:37 0 How to subtract one year from a date in PHP?Subtract 1 year from date. $date = "2020-01-06"; echo date('Y-m-d', strtotime($date.
How to add 30 days in date in PHP?Method 2: Using date_add() Function: The date_add() function is used to add days, months, years, hours, minutes and seconds. Syntax: date_add(object, interval);
How to add a year to date in PHP?Example 1: PHP Add Year to Date. index.php. $date = "2022-02-01"; $newDate = date('Y-m-d', strtotime($date. ' + 5 years')); ... . Output: 2027-02-01.. index.php. $newDate = date('Y-m-d', strtotime(' + 5 years')); echo $newDate; ?>. Output: Read Also: How to Add Months to Date in PHP? 2026-03-01. i hope it can help you.... How to get last year date in PHP?To get the previous year in PHP. first, we need to access the current year using the built-in date("Y") function then we need to subtract it with minus 1. The date("Y") function returns the current year in four-digit(2021) string format according to the user's local time.
|