Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to convert month to number in python

import calendar

months = {month: index for index, month in enumerate(calendar.month_abbr) if month}

# {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6, 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}
Comment

python month number from date

import datetime
date = '2021-05-21 11:22:03'
datem = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
print(datem.day)        # 25
print(datem.month)      # 5
print(datem.year)       # 2021
print(datem.hour)       # 11
print(datem.minute)     # 22
print(datem.second)     # 3
Comment

converting month number to month name python

months_in_year = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
date = '2021-11-21 11:22:03'
month = date.dt.month
print(month)
#Output
11

month_name = months_in_year [month - 1]
print(month_name)
#Output
November
Comment

PREVIOUS NEXT
Code Example
Python :: iloc[ ] slicing 
Python :: fight club is the best movie ever 
Python :: To install the C++ and Python Messaging APIs: 
Python :: How to import modules in Python? 
Python :: py random sample 
Python :: how to save a count countvectorizer model in python 
Python :: install plotly manually 
Python :: Python Raw string using r prefix 
Python :: numpy subtraction operation using numpy functions 
Python :: ascci value pyth 
Python :: send2trash 
Python :: input what is your name python 
Python :: can you use pop on a string 
Python :: how to make an app that sends email in python 
Python :: NLP text summarization with LSA 
Python :: x and y in python 
Python :: how to select the three highest entries within a category in pandas 
Python :: kite order syntax 
Python :: Odoo Module ACL(Access Controls List) 
Python :: Customizing multiple plots in the same figure 
Python :: get a list of colors that appear of the image python 
Python :: Tree : Top View 
Python :: ex: git push new local repo 
Python :: How to Use the abs() Function with a Complex Number Argument 
Python :: python detect ranges in list 
Python :: como tornar uma string numa lista 
Python :: hwoto neglect if any exception happening in python 
Python :: site:github.com python ssh 
Python :: couchbase python 
Python :: python measure volum from audio file 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =