Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get current month 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

how to get the year and month in python

import calander
ear = int(input("Input the year:- "))
Month = int(input("Input the month:- "))
print(calendar.month(y, m))
Comment

PREVIOUS NEXT
Code Example
Python :: how to add images in hml while using flask 
Python :: how to plot 2 decimal values in axis python 
Python :: get size of window tkinter 
Python :: python cmd colors 
Python :: pandas drop empty rows 
Python :: converting a csv into python list 
Python :: python import json into pymongo 
Python :: import numpy Illegal instruction (core dumped) 
Python :: extract frames from video python 
Python :: plt plot circle 
Python :: python object to json file 
Python :: tkinter labelframe 
Python :: get list of all files in folder and subfolders python 
Python :: List comprehension - list files with extension in a directory 
Python :: install python 3.6 mac brew 
Python :: pandas multiple string contains 
Python :: how to read csv file online into pandas 
Python :: required validator python WTForms 
Python :: flask development mode 
Python :: np not defined 
Python :: py for line in file 
Python :: LookupError: unknown encoding: idna python 
Python :: how to do key sensing in python 
Python :: sort list by attribute python 
Python :: how to do label encoding in multiple column at once 
Python :: mp4 to wav python 
Python :: how to use random in python 
Python :: how to add numbers in python using for loop 
Python :: edge detection opencv python 
Python :: convert all values in array into float 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =