-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdateandtime.py
29 lines (24 loc) · 1.09 KB
/
dateandtime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# bring in the date and time functions
import datetime
from datetime import *
# Take today's date and format it
formattedtoday = date.today().strftime("%A %B %d %Y")
print ("Today's date is: ", formattedtoday)
today = date.today()
# Take a previous date and format it
previousday = date(1994, 01, 29)
formattedpreviousday = previousday.strftime("%A %B %d %Y")
print ("A previous day is: ", formattedpreviousday)
# calculate the difference between the 2 days
difference = (today - previousday).days
print ("The number of days between the previous day and today is: ", difference)
# calculate the difference using integers
# 1st convert the previous day to an integer
previousdayinteger = date.toordinal(previousday)
# then convert today to an integer
todayinteger = date.toordinal(today)
# calculate the difference between them
integerdifference = todayinteger - previousdayinteger
print ("Using integers, the difference in days between the previous day and today is: ", integerdifference)
formattedtimedate = datetime.now().strftime("%A %B %d %Y %H %M %S")
print ("Today's date and time is: ", formattedtimedate)