Python Date functions

Importing datetime library

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

Getting day , month , year and weekday

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

More Instance methods:

toodinal()Proleptic Gregorian ordinal of the date
timetuple()Details of date and time as a tuple
strftime()String to datetime object
resolution()String to datetime object
replace()String to datetime object
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
dt=datetime.datetime(2019,5,24)
print(dt.day,dt.month,dt.year) # 24 5 2019 
2nd Saturday Display 2nd and 4th Saturday of the month
All timedelta objects relativedelta


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer