Get last year in php
How am I able to get the value of the previous year using PHP. Are there any predefined functions for it? Show
wattostudios 8,60613 gold badges42 silver badges57 bronze badges asked May 5, 2011 at 10:37
2 try
answered May 5, 2011 at 10:47
diEchodiEcho 52.6k41 gold badges172 silver badges242 bronze badges 1 There are many ways, you can either take away the amount of seconds in a year from
Or if you'd prefer, use the PHPs clever
Or even like others have said, if it's from todays year just do answered May 5, 2011 at 10:45
DunhamzzzDunhamzzz 14.4k3 gold badges48 silver badges74 bronze badges 1 Shortest approach:
answered Sep 25, 2017 at 10:33
michal.jakubeczymichal.jakubeczy 6,8761 gold badge52 silver badges57 bronze badges 1
answered May 5, 2011 at 10:44
jimyjimy 4,7903 gold badges34 silver badges51 bronze badges you can give a value of the input tag as :
answered Jun 27, 2019 at 22:28
0 If you want to display the entire date exactly 1 year ago, including the month and year:
Kirk Beard 9,17612 gold badges43 silver badges46 bronze badges answered Jan 24, 2013 at 14:56
Midnightly CoderMidnightly Coder 1,0431 gold badge11 silver badges22 bronze badges
answered Mar 31 at 5:26
Try This
answered Nov 7, 2017 at 9:56
This thread needs an update. Nowadays you would use the PHP date-time object and do something like this:
answered Apr 25, 2020 at 17:20
HappyCoderHappyCoder 5,7076 gold badges40 silver badges72 bronze badges How to display previous year 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.
How get current year from last year in PHP?php echo date("M d Y", strtotime("-1 year")); ?> Show activity on this post.
How to get year PHP?To get the current year using PHP's date function, you can pass in the “Y” format character like so: //Getting the current year using //PHP's date function. $year = date("Y"); echo $year; The example above will print out the full 4-digit representation of the current year.
|