#!/usr/bin/env python3 
################################################################################### 
# Python date functions 
# using datetime module (datetime and timedelta)
################################################################################### 
print("Content-Type: text/html \n")     #http header with newline char (required for the web)

from datetime import datetime, timedelta
 
print('<pre>')                          #to produce better display on the web 

now   = datetime.now()                              #create date obj for today
gmt   = datetime.utcnow()                           #create date obj for GMT now
other = datetime(2022,12,1,15,30,43,100000)         #create date obj for another day

print("Working with Dates & Time")
print("Today's date: ", now)   
print("GMT now:      ", gmt)   
print("Another date: ", other)
print()

print("year:       ", now.year)  
print("month:      ", now.month)
print("day:        ", now.day)   
print("hour:       ", now.hour)  
print("minute:     ", now.minute)
print("second:     ", now.second) 
print("microsecond:", now.microsecond)
print("GMT offset: ", gmt - now)
print() 

print("Proper Greeting: ", end='')
if   now.hour < 12: print("Good Morning") 
elif now.hour < 18: print("Good Afternoon")
else:               print("Good Evening") 

print()
print("Date/time now:   ", now.strftime('%c') )                        #Sun Jan dd hh:mm:ss yyyy
print("The date only    ", now.strftime('%A, %B, %d/%m/%Y') )          #Sunday, April, dd/mm/yyyy 
print("The time is:     ", now.strftime('%H:%M:%S %I:%M %p') )         #h24:mm:ss h12:mm AM    
print("Other Components ", now.strftime('%a %b %j %w %U %x %X %y') )   #Sun Jan JulianDay DayNum WeekNum m/d/y h:m:s yy  
print()

other2 = datetime.now()
other2 = other.replace(other2.year,12,2,15,21,43)                  		#changing a date            
print("Yet another date, using replace(): ", other2)
print()