• 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
  • Ruby
  • 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.  How to Create an Empty Array in php
  • 2.  Get Last Day of Month in php
  • 3.  php ceil – Round Up and Find the Ceiling of a Number in php
  • 4.  php session_destroy() – Delete Session File Where Session Data is Stored
  • 5.  Delete Cookie Using php
  • 6.  Remove First Character from String Using php
  • 7.  Using strtoupper() in php to Convert String to Uppercase
  • 8.  Remove String from String in php with str_replace()
  • 9.  PHP random_int() Function – Generate Random Integers in PHP
  • 10.  Get Query String from URL in php

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

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

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 © 2023 · The Programming Expert · About · Privacy Policy

x