Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get month name from number

How can I get the month name from the month number?

For instance, if I have 3, I want to return march

date.tm_month() 

How to get the string march?

like image 877
Rajeev Avatar asked Jul 02 '11 14:07

Rajeev


People also ask

How do I extract the month from a number?

The MONTH function takes just one argument, the date from which to extract the month. In the example shown, the formula is: = MONTH ( B4 ) where B4 contains the dateJanuary 5, 2016. The MONTH function returns the number 1 representing the month(...

How do I convert month number to month name in Excel?

Please do as follows: Select a blank cell next to the sales table, type the formula =TEXT(A2*29,"mmm") (Note: A2 is the first number of the Month list you will convert to month name), and then drag the AutoFill Handle down to other cells. Now you will see the numbers (from 1 to 12) are converted to normal month names.


1 Answers

import datetime mydate = datetime.datetime.now() mydate.strftime("%B") 

Returns: December

Some more info on the Python doc website


[EDIT : great comment from @GiriB] You can also use %b which returns the short notation for month name.

mydate.strftime("%b") 

For the example above, it would return Dec.

like image 183
JMax Avatar answered Sep 21 '22 03:09

JMax