Python solution: finding the day of the week

given a date in the yyyy-mm-dd format
2025-11-06 11:26
// updated 2025-11-25 09:10

Given a date in the yyyy-mm-dd format, with the help of the datetime library, we can easily find the weekday:

import datetime

def get_weekday(date_string):

  # datetime accepts only integers without leading zeroes
  year = int(date_string[0:4])
  month = int(date_string[5:7])
  day = int(date_string[8:10])
  
  date = datetime.datetime(year, month, day)

  # %A gives us the weekday
  return date.strftime("%A")

# any given date
mydate = '2026-01-01'
print(mydate + ' is a ' + get_weekday(mydate))

# today's date
rightnow = str(datetime.datetime.now())[0:10]
print('Today is a ' + get_weekday(rightnow))
âŦ…ī¸ older (posts)
đŸĒļ 2025-10
newer (posts) âžĄī¸
On the good school 🎓