datetime

Refer to
https://docs.python.org/3/library/datetime.html

Use the datetime module to write a program that gets the current date and prints the day of
the week.
datetime.now
datetime.weekday() :Return the day of the week as an integer, where Monday is 0 and Sunday is 6. The same as self.date().weekday(). 


from datetime import datetime as dt

ct = dt.now()
print("Week day", ct.weekday())

Write a program that takes a birthday as input and prints the user’s age and the number of
days, hours, minutes and seconds until their next birthday.

use the timedelta object that is created with the difference.


from datetime import date

ct = dt.now()

print("Birthday is on 9th May 2020")
bday_this_year=dt(ct.year,5,9)
if bday_this_year > ct:
   tb=bday_this_year - ct

print(tb, "to birthday"))


Comments

Popular posts from this blog

TYL - Food Corner Program

TYL - Salary Hike - Python Problem

5 Questions for TYL on Strings(check if two string are anagrams)