Change language

How to convert number to month name in PHP?

Method 1: Using the function mktime() :Function mktime() - it is a built-in function in PHP that is used to return a Unix timestamp for a date. A timestamp returns a long integer containing the number of seconds between the Unix epoch (January 1, 1970, 00:00:00 GMT) and the specified time. The hours, minutes, seconds, month, day, and year are sent as parameters to the mktime() function, and it returns an integer Unix timestamp on success and False on failure.Syntax:
int mktime ($hour, $minute, $second, $month, $day, $year, $is_dst)
// PHP program for converting date to month name 
// Declare the month number and initialize it $month_num = 12;  
// Use the mktime() and date() functions for
// convert number to month name $month_name = date ( "F" , mktime (0, 0, 0, $month_num , 10));  
// Display month name echo $month_name . "" ;  
December  Method 2: Using  DateTime::createFromFormat() :DateTime function: : createFromFormat() is a built-in function in php that is used to parse the time string according to the specified format. This function takes three parameters and returns a new DateTime on success or false on failure.Syntax:
DateTime::createFromFormat ($format, $time, $timezone)
Example : // PHP program to convert date to month name 
// Declare the month number and initialize it $monthNum = 4;  
// Create a date object to store the DateTime format $dateObj = DateTime::createFromFormat ( ’! m’ , $monthNum );  
// Store the month name in a variable $monthName = $dateObj -> format ( ’ F’ );  
// Show output echo $monthName . " " ;  



Best laptop for Sims 4


Best laptop for Zoom


Best laptop for Minecraft


Best laptop for engineering student


Best laptop for development


Best laptop for Cricut Maker


Best laptop for hacking


Best laptop for Machine Learning


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers


Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method