i need help

Dani AI

Generated

For a cross-platform, ready-to-run Python solution (since this thread is tagged Python), here is a small script that accepts several common date formats and prints the weekday name. ’s shell suggestion is a fine quick fix on Unix-like systems, but a Python script works the same on Windows, macOS, or Linux and is easy to extend.

#!/usr/bin/env python3
from datetime import datetime
import sys

FORMATS = (
    '%Y-%m-%d', '%Y/%m/%d', '%Y%m%d',
    '%d/%m/%Y', '%d-%m-%Y',
    '%m/%d/%Y', '%m-%d-%Y',
)

def weekday_name(date_str):
    s = date_str.strip()
    for fmt in FORMATS:
        try:
            dt = datetime.strptime(s, fmt)
            return dt.strftime('%A')  # full weekday name
        except ValueError:
            continue
    raise ValueError("Unknown date format. Try ISO like '2026-01-20' or one of: " + ", ".join(FORMATS))

if __name__ == '__main__':
    if len(sys.argv) > 1:
        print(weekday_name(sys.argv[1]))
    else:
        print(weekday_name(input("Date: ")))

Notes and tips: prefer ISO 8601 input (YYYY-MM-DD) to avoid ambiguity between DD/MM/YYYY and MM/DD/YYYY. datetime supports years 1..9999 and uses the proleptic Gregorian calendar (so results for very old dates follow the Gregorian rules even before 1582). strftime('%A') returns the weekday name in the current locale; if you need fixed English names regardless of locale, map datetime.weekday() (0–6) to a hardcoded list. For more forgiving parsing of free-form dates, consider the third-party package python-dateutil (pip install python-dateutil) and its dateutil.parser.parse.

Troubleshooting: if you get ValueError, check for stray spaces, unexpected separators, or month-name formats (add '%B %d, %Y' to FORMATS for "January 2, 2026"). To support other input styles, add formats to FORMATS or switch to dateutil for automatic parsing.

Recommended Answers

All 2 Replies

a program that take any date and gives the name of day

Date already does this, just replace the date (ie 2004/05/07) with the one you want.

$ date -d"20040507" +"%A"

Friday
commented: TGI pty +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.