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-06 18:57

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 (in snippets)
🏔️ Shorthand cheatsheet for Alpine.js
⬅️ older (in code)
🐍 Python sets
⬅️ older (posts)
🐍 Python sets