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

PREVIOUS NEXT
Code Example
Python :: dictionaries to http data python 
Python :: python convert file into list 
Python :: python -m pip install --upgrade 
Python :: how to create progress bar python 
Python :: How do you sum consecutive numbers in Python? 
Python :: remove all occurrences of a character in a list python 
Python :: numpy random float array between 0 and 1 
Python :: creating a 50 day and 100 day moving average python 
Python :: counter in sort python 
Python :: How to find least common multiple of two numbers in Python 
Python :: python remove read only file 
Python :: nltk stop words 
Python :: python read toml file 
Python :: django import model from another app 
Python :: pandas shift one column 
Python :: len table python 
Python :: flask development mode 
Python :: python print list with newline 
Python :: save image python 
Python :: python how to unnest a nested list 
Python :: create new thread python 
Python :: python random email generator 
Python :: python degrees to radians 
Python :: pymysql check if table exists 
Python :: python discord discord.py disable remove help command 
Python :: python make temp file 
Python :: try datetime python 
Python :: python divide every element in a list by a number 
Python :: selenium quit browser python 
Python :: pandas show all dataframe 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =