Friday, 15 April 2022

P#25 DATE TIME

 Python - Date and Time


import datetime

print('The Date Today is :', datetime.datetime.today())


date_today = datetime.date.today()

print(date_today)

print('This Year :', date_today.year)

print('This Month :', date_today.month)

print('Month Name:',date_today.strftime('%B'))

print('This Week Day :', date_today.day)

print('Week Day Name:',date_today.strftime('%A'))

"""
The Date Today is : 2022-04-15 22:56:14.461386
2022-04-15
This Year : 2022
This Month : 4
Month Name: April
This Week Day : 15
Week Day Name: Friday
"""


DATE TIME ARITHMETIC

import datetime

# First Date
day1 = datetime.date(2020, 2, 12)
print('day1:', day1.ctime())

# Second Date
day2 = datetime.date(2019, 8, 18)
print ('day2:', day2.ctime())

# Difference between the dates
print('Number of Days:', day1 - day2)

date_today = datetime.date.today()

# Create a delta of Four Days
no_of_days = datetime.timedelta(days=4)

# Use Delta for Past Date -
before_four_days = date_today - no_of_days
print('Before Four Days:', before_four_days)

# Use Delta for future Date +
after_four_days = date_today + no_of_days
print('After Four Days:', after_four_days)

"""
day1: Wed Feb 12 00:00:00 2020
day2: Sun Aug 18 00:00:00 2019
Number of Days: 178 days, 0:00:00
Before Four Days: 2022-04-11
After Four Days: 2022-04-19
"""

Happy Learning at AMET ODL!👦👧👥👭👬

No comments:

Post a Comment

Making Prompts for Profile Web Site

  Prompt: Can you create prompt to craft better draft in a given topic. Response: Sure! Could you please specify the topic for which you...