World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
Download our e-book of Introduction To Python
4.5 (1,292 Ratings)
559 Learners
Jigisha Sata
a year ago
import datetime
print('Today’s date and time is : ',
datetime.datetime.today())
date = datetime.date.today()
print(date)
print('Current Year :', date.year)
print ('Current Month :', date.month)
print ('Current Month Name:',date.strftime('%B'))
print ('Current Week Day :', date.day)
print ('Week Day Name :',date.strftime('%A'))
Today"s date and time is : 2021-07-07 09:37:26.512851
2021-07-07
Current Year : 2021
Current Month : 7
Current Month Name: July
Current Week Day : 7
Week Day Name : Wednesday
import datetime
d1 = datetime.date(2020,7,3) # First Date
print('Day 1 :', d1.ctime())
d2 = datetime.date(2019, 8, 18) # Second Date
print('Day 2 :', d2.ctime())
print('Number of Days:', d1-d2) # difference between the dates
today = datetime.date.today()
no_of_days = datetime.timedelta(days=3)
# Delta for Past Date
before_three_days = today - no_of_days
print('Before three Days:', before_three_days)
# Delta for future Date
after_three_days = today + no_of_days
print('After three Days:',after_three_days)
Day 1 : Fri Jul 3 00:00:00 2020
Day 2 : Sun Aug 18 00:00:00 2019
Number of Days: 320 days, 0:00:00
Before three Days: 2021-07-04
After three Days: 2021-07-10
import datetime
today = datetime.date.today()
print('Today is: ',today)
no_of_days = datetime.timedelta(days=3)
before_three_days = today - no_of_days
print('Before three Days:', before_three_days)
after_three_days = today + no_of_days
d1 = datetime.date(2019,5,5)
print( 'Date 1 :',d1)
if d1 == before_three_days :
print ('Same Dates')
if today > d1:
print ('Past Date')
if d1 < after_three_days:
print ('Future Date')
Today is: 2021-07-07
Before three Days: 2021-07-04
Date 1 : 2019-05-05
Past Date
Future Date