diff --git a/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py b/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py index 243f396..839c132 100644 --- a/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py +++ b/Day 2 - Python Datetime objects and Timedelta/Q1_BeforeChristmas.py @@ -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 diff --git a/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py b/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py index 91f7501..f1047db 100644 --- a/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py +++ b/Day 2 - Python Datetime objects and Timedelta/Q2_TimeDifference.py @@ -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) diff --git a/Day 2 - Python Datetime objects and Timedelta/Thank you.png b/Day 2 - Python Datetime objects and Timedelta/Thank you.png deleted file mode 100644 index 6694cb8..0000000 Binary files a/Day 2 - Python Datetime objects and Timedelta/Thank you.png and /dev/null differ diff --git a/Day 3 - Datetime strftime and strptime/Q1Solution.py b/Day 3 - Datetime strftime and strptime/Q1Solution.py new file mode 100644 index 0000000..fc73ca1 --- /dev/null +++ b/Day 3 - Datetime strftime and strptime/Q1Solution.py @@ -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")) \ No newline at end of file diff --git a/Day 3 - Datetime strftime and strptime/Q2_Solution.py b/Day 3 - Datetime strftime and strptime/Q2_Solution.py new file mode 100644 index 0000000..37dbff3 --- /dev/null +++ b/Day 3 - Datetime strftime and strptime/Q2_Solution.py @@ -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"))) diff --git a/Day 4 - Datetime Timezone and Unix Timestamp/Q1_ConvertUnixTimeStampToReadable.py b/Day 4 - Datetime Timezone and Unix Timestamp/Q1_ConvertUnixTimeStampToReadable.py new file mode 100644 index 0000000..8795797 --- /dev/null +++ b/Day 4 - Datetime Timezone and Unix Timestamp/Q1_ConvertUnixTimeStampToReadable.py @@ -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")) +