Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
"""
1. What date is 3 weeks and 4 days before Christmas?
Solution provided by Sanjay Siddha
"""



from datetime import timedelta, date


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
2. What is the time difference between January 1, 2019 11 AM
and May 20, 2020 22.30 PM? Mention both the days and time
in your solution.
Solution provided by Sanjay Siddha
"""


from datetime import datetime, timedelta

future_date = datetime(year=2020, month=5, day=20, hour=22, minute=30)
Expand Down
Binary file not shown.
9 changes: 9 additions & 0 deletions Day 3 - Datetime strftime and strptime/Q1Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# 1. Convert 9 AM of International Women's day of 2020 to the following format.
# --> "Sunday, 8 March 2020"


from datetime import datetime

womens_day = datetime(year=2020, month=3, day=8)
print(datetime.strftime(womens_day, "%A, %d %B %Y"))
29 changes: 29 additions & 0 deletions Day 3 - Datetime strftime and strptime/Q2_Solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 2. Convert the following date string to datetime object.
# --> "Jan 20, 2019 9:30 AM"

from datetime import datetime

# Explanation:
# 1. Given dateString format is like - month date, year hour:minute AM in a string format.
# 2. Whenever you need to convert a string to datetime, then all the component inside the string needs to be used for \
# constructing datetime object

# Example,
'''
sampleDateString = "2019/22/08"
print(datetime.strptime(sampleDateString, "%Y/%m/"))

Output:
ValueError: unconverted data remains: 08

Working code:
print(datetime.strptime(sampleDateString, "%Y/%m/%d"))

Output:
2019-08-22 00:00:00

if you see the above output, it also prints time as 00:00:00
'''

dateString = "Jan 20, 2019 9:30 AM"
print(type(datetime.strptime(dateString, "b %d, %Y %-I:%M %p")))
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 1) Write a Python program to convert the current unix timestamp
# string to readable date and time in the below format
#
# Desired format - "June 15, 2019 7.30 PM"

from datetime import datetime

current_timestamp = datetime.now().timestamp()
readable_format = datetime.fromtimestamp(current_timestamp)
print(datetime.strftime(readable_format, "%B %d, %Y %-I:%M %p"))