How can i get month in php?
I want to be able to figure out the month of the current date variable. I'm ex vb.net and the way to do it there is just Show Thanks, Jonesy I used This is what I wanted, question now is how do I compare this to an int since
John 11.9k11 gold badges90 silver badges156 bronze badges asked Sep 22, 2010 at 9:51
iamjonesyiamjonesy 24.2k40 gold badges134 silver badges206 bronze badges 2 See http://php.net/date
Update
....see the docs link for even more options.
answered Sep 22, 2010 at 9:54
What does your "data variable" look like? If it's like this:
You can simply do:
For more information, take a look at date and strtotime. EDIT: To compare with an int, just do a Alternatively, try one of these:
Or something weird using ltrim, round, floor... but date_format() with "n" would be the best.
Kwido 1,3728 silver badges21 bronze badges answered Sep 22, 2010 at 9:56
oezioezi 50k10 gold badges97 silver badges115 bronze badges 1
answered Sep 22, 2010 at 9:56
Pramendra GuptaPramendra Gupta 14.4k4 gold badges32 silver badges34 bronze badges as date_format uses the same format as date ( http://www.php.net/manual/en/function.date.php ) the "Numeric representation of a month, without leading zeros" is a lowercase n .. so
answered Sep 22, 2010 at 10:45
HannesHannes 7,9474 gold badges32 silver badges51 bronze badges As it's not specified if you mean the system's current date or the date held in a variable, I'll answer for latter with an example.
answered Apr 7, 2018 at 4:59
J-a-n-u-sJ-a-n-u-s 1,35916 silver badges20 bronze badges 1 To compare with an int do this:
answered Feb 29, 2020 at 16:20
e102e102 657 bronze badges How can I get current month in PHP?php $transdate = date('m-d-Y', time()); echo $transdate; $month = date('m', strtotime($transdate)); if ($month == "12") { echo "
December is the month :)"; } else { echo " The month is probably not December"; } ?> How can I get current month number?Use the new Date() constructor to get a date object. Call the getMonth() method on the object and add 1 to the result. The getMonth method returns a zero-based month index so adding 1 returns the current month.
How do I get the month start and end in PHP?php echo 'First Date = ' . date('Y-m-01') . '
'; echo 'Last Date = ' . date('Y-m-t') . How can I get 30 Day date in PHP?php $next_due_date = date('05/06/2016', strtotime("+30 days")); echo $next_due_date; ?> But it is returning to "05/06/2016" only!
|