Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get current month name python

import calendar
from datetime import date

current_month_name = calendar.month_name[date.today().month]
# the variable will hold something like 'April'

#if you want the abbreviated version:
current_month_name_abbreviated = calendar.month_abbr[date.today().month]
# the variable will hold something like 'Apr' now instead of 'April'
Comment

python get current month

from datetime import datetime

current_month = datetime.now().strftime('%m') // 02 //This is 0 padded
current_month_text = datetime.now().strftime('%h') // Feb
current_month_text = datetime.now().strftime('%B') // February

current_day = datetime.now().strftime('%d')   // 23 //This is also padded
current_day_text = datetime.now().strftime('%a')  // Fri
current_day_full_text = datetime.now().strftime('%A')  // Friday

current_weekday_day_of_today = datetime.now().strftime('%w') //5  Where 0 is Sunday and 6 is Saturday.

current_year_full = datetime.now().strftime('%Y')  // 2018
current_year_short = datetime.now().strftime('%y')  // 18 without century

current_second= datetime.now().strftime('%S') //53
current_minute = datetime.now().strftime('%M') //38
current_hour = datetime.now().strftime('%H') //16 like 4pm
current_hour = datetime.now().strftime('%I') // 04 pm

current_hour_am_pm = datetime.now().strftime('%p') // 4 pm

current_microseconds = datetime.now().strftime('%f') // 623596 Rarely we need.

current_timzone = datetime.now().strftime('%Z') // UTC, EST, CST etc. (empty string if the object is naive).
Comment

python get current month

Use:

from datetime import datetime
today = datetime.today()
datem = datetime(today.year, today.month, 1)
I assume you want the first of the month.
Comment

PREVIOUS NEXT
Code Example
Python :: python swap two elements 
Python :: while loop user input python 
Python :: selectfield flask wtf 
Python :: append method linked list python 
Python :: list of df to df 
Python :: blank=True 
Python :: python how to open a file in a different directory in mac 
Python :: pandas append index ignore 
Python :: save a file as a pickle 
Python :: python loop x times 
Python :: how to use variables in string in python 
Python :: Python loop to run for certain amount of seconds 
Python :: how to set up a postgress database for your django projecrt 
Python :: how to send emails in python 
Python :: Concat and Append DFs Python 
Python :: tkinter new line in text 
Python :: python how to change an element in a multi dimensional list 
Python :: torchvision.transforms 
Python :: pyqt5 qlineedit on change 
Python :: how to smooth a function in python 
Python :: how to delete a specific line in a file 
Python :: pandas apply pass in arguments 
Python :: python read from stdin 
Python :: selenium python class contains 
Python :: case statement in pandas 
Python :: python jokes 
Python :: how to get only certain columns in pandas 
Python :: how to add three conditions in np.where in pandas dataframe 
Python :: model o weight 
Python :: is flask open source 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =