Python Date functions

Importing datetime library

from datetime import date
Today's date
from  datetime import date
dt = 
print(dt)    # 2019-09-16

Getting day , month , year and weekday

Commonly used instances
from  datetime import date
print("Today day : ",
print("Today month : ",
print("Today year : ",
print("Today weekday : ",
Today day :  16
Today month :  9
Today year :  2019
Today weekday :  0


from datetime import timedelta,date,datetime
dt = + timedelta(days=1) # tomorrow 


dt = + timedelta(days=-1) # Yesterday

More Instance methods:

toodinal()Proleptic Gregorian ordinal of the date
timetuple()Details of date and time as a tuple
strftime()Date & time to String
strptime()String to datetime object
resolution()Minimum difference between String to datetime object
replace()Update date object with new parameters
max() & min()Maximum and Minimum representable date
isoweekday()Day of the week as integer
isocalendar()ISO year, ISO week number & ISO weekday
fromtimestamp()Getting date and time by using timestamp
fromordinal()Getting date by using ordinal
fromisoformat()Getting date by using iso fomat date string
Creating a date object
import datetime
print(,dt.month,dt.year) # 24 5 2019 
2nd Saturday Display 2nd and 4th Saturday of the month
calendarCalendar module to Create yearly or monthly Calendars
All timedelta objects relativedelta


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2021 All rights reserved worldwide Privacy Policy Disclaimer