mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-18 17:20:16 +00:00
cecf43d648
* Pyupgrade to Python 3.9 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
28 lines
776 B
Python
28 lines
776 B
Python
from calendar import day_name
|
|
from datetime import datetime
|
|
|
|
|
|
def date_to_weekday(inp_date: str) -> str:
|
|
"""
|
|
It returns the day name of the given date string.
|
|
:param inp_date:
|
|
:return: String
|
|
>>> date_to_weekday("7/8/2035")
|
|
'Tuesday'
|
|
>>> date_to_weekday("7/8/2021")
|
|
'Saturday'
|
|
>>> date_to_weekday("1/1/2021")
|
|
'Friday'
|
|
"""
|
|
day, month, year = (int(x) for x in inp_date.split("/"))
|
|
if year % 100 == 0:
|
|
year = "00"
|
|
new_base_date: str = f"{day}/{month}/{year%100} 0:0:0"
|
|
date_time_obj: datetime.date = datetime.strptime(new_base_date, "%d/%m/%y %H:%M:%S")
|
|
out_put_day: int = date_time_obj.weekday()
|
|
return day_name[out_put_day]
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(date_to_weekday("1/1/2021"), end=" ")
|