Source Code Snippets of "Time.py"

Mike Dinder

The entire contents of the "Time.py" file as code examples with syntax highlighting

Auto Generated Using Generate_HTML.py script to auto format each of these pages in a standardized template.

On smaller viewports/windows, please scroll or use your touch/finger to scroll left to right to view all the code displayed.

                                        # Various Time/Date operations and functions
import calendar
import datetime
import time

# Get the current Date and Time
now = datetime.datetime.now()
now_2 = time.ctime()

print("The Current Date and Time is...")
print(now.strftime("%B %A %m/%d/%y %I:%M%p"))  # Outputs as January Monday 01/12/26 03:55PM
print(now_2)

print('--------------------------------------------------')

print("Show a calendar for a given month and year.")

year = int(input("Enter the Year in YYYY format: "))
month = int(input("Enter the Month in MM numeric format: "))

print(f'Shows the Month Only for {month} of {year}')
print(calendar.month(year, month))

print('--------------------------------------------------')

print(f'Shows the Full Year {year}')
print(calendar.calendar(year))

print('--------------------------------------------------')

print("Number of days between two dates.")

date_1 = input("Please enter the start date in mm/dd/yyyy format: ")
date_2 = input("Please enter the end date in mm/dd/yyyy format: ")
format_pattern = "%m/%d/%Y"

start_object = datetime.datetime.strptime(date_1, format_pattern)
end_object = datetime.datetime.strptime(date_2, format_pattern)

if start_object > end_object:
    delta = start_object - end_object
elif start_object < end_object:
    delta = end_object - start_object
else:
    delta = 0

print(f"The number of days between the two dates ({date_1} & {date_2}) is...")
print(delta)


                                        

Runs the entire script above. Open your Console Window in Inspect Code to view the output of the script above.

A prompt popup will ask you for various input() commands.

Python in Your Browser

Client-side execution via Pyodide · No server · Full stdlib · numpy, pandas, matplotlib available via micropip

Mobile users will want to use this method. Copy snippets or the entire script from above. You may also copy this script exactly as it is shown and you can run it on your own machine using the Command-Line Interface (CLI).

Loading Pyodide...
>>>
Enter run Shift+Enter new line ↑↓ history