• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • VBA
  • About
You are here: Home / PHP / Get Current Month of Date in php

Get Current Month of Date in php

April 27, 2022 Leave a Comment

To get the name of the current month in php, you can use the php date() function and pass “F”.

$month_name = date("F");

echo $month_name;

// Output:
April

If you want to get the current month number, you can use the php idate() function and pass ‘m’.

$month_number = idate('m');

echo $month_number ;

// Output:
4

When working with dates in php, the ability to easily get specific information or format our dates a certain way can be very valuable.

One piece of information which is useful is the month of a date.

We can easily get the current month from a date in php with the php date() function.

If you pass “F” to date, you get the full textual representation of the month of a given date.

Below shows how you can get the month name from a date in php.

$month_name = date('F');

echo $month_name;

// Output:
April

Getting the Current Month Number in php with idate()

There is also a php function which allows you to get the month number of the current month. The php idate() function formats a local time or date as an integer.

With idate(), we can get the current month number as shown below in the following php code.

$month_number = idate('m');

echo $month_number ;

// Output:
4

Hopefully this article has helped you understand how to get the current month in php.

Other Articles You'll Also Like:

  • 1.  Get First Element of Array in php
  • 2.  php str_split() – Convert String into Array of Equal Length Substrings
  • 3.  php array_merge() – Merge One or More Arrays Together by Appending
  • 4.  php atan – Find Arctangent and Inverse Tangent of Number
  • 5.  php atanh – Find Hyperbolic Arctangent of Number Using atanh() Function
  • 6.  How to Add Items to Array in php
  • 7.  Check if Variable Exists in php with isset() Function
  • 8.  php array_key_exists() Function – Check if Key Exists in Array
  • 9.  php preg_match_all – Get All Matches of Pattern in String
  • 10.  Remove Duplicates from Array in php with array_unique()

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

The Programming Expert is a compilation of hundreds of code snippets to help you find solutions to your problems in Python, JavaScript, PHP, HTML, SAS, and more.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2022 · The Programming Expert · About · Privacy Policy