sqlcmd.net validated sql reference
intermediate date-time MySQL MariaDB SQL Server PostgreSQL SQLite

Get The Day Of Week From A Date

Return the weekday number or name for a date using engine-specific date functions.

Docker-validated Not currently validation-green

Label each order with its weekday name

March 15, 2024 was a Friday, and March 16 was a Saturday. The query formats those dates as weekday labels.

MySQL MariaDB
Engine-specific syntax
Setup
CREATE TABLE orders (id INT, ordered_at DATE);

INSERT INTO
  orders
VALUES
  (1, '2024-03-15'),
  (2, '2024-03-16');
SQL
SELECT
  id,
  DAYNAME (ordered_at) AS weekday_name
FROM
  orders
ORDER BY
  id;
idweekday_name
1Friday
2Saturday
SQL Server
Engine-specific syntax
Setup
CREATE TABLE orders (id INT, ordered_at DATE);

INSERT INTO
  orders
VALUES
  (1, '2024-03-15'),
  (2, '2024-03-16');
SQL
SELECT
  id,
  DATENAME (weekday, ordered_at) AS weekday_name
FROM
  orders
ORDER BY
  id;
idweekday_name
1Friday
2Saturday
PostgreSQL
Engine-specific syntax
Setup
CREATE TABLE orders (id INT, ordered_at DATE);

INSERT INTO
  orders
VALUES
  (1, '2024-03-15'),
  (2, '2024-03-16');
SQL
SELECT
  id,
  TO_CHAR (ordered_at, 'FMDay') AS weekday_name
FROM
  orders
ORDER BY
  id;
idweekday_name
1Friday
2Saturday
SQLite
Engine-specific syntax
Setup
CREATE TABLE orders (id INT, ordered_at TEXT);

INSERT INTO
  orders
VALUES
  (1, '2024-03-15'),
  (2, '2024-03-16');
SQL
SELECT
  id,
  CASE strftime ('%w', ordered_at)
    WHEN '0' THEN 'Sunday'
    WHEN '1' THEN 'Monday'
    WHEN '2' THEN 'Tuesday'
    WHEN '3' THEN 'Wednesday'
    WHEN '4' THEN 'Thursday'
    WHEN '5' THEN 'Friday'
    WHEN '6' THEN 'Saturday'
  END AS weekday_name
FROM
  orders
ORDER BY
  id;
idweekday_name
1Friday
2Saturday

SQLite maps strftime('%w') manually because it has no built-in weekday-name function.

Where this command helps.

  • grouping activity by weekday
  • filtering weekend or weekday records

What the command is doing.

Weekday extraction is useful for calendars, staffing reports, and weekend filters. SQL engines disagree on both function names and numbering conventions, so normalize the result if it will be compared across databases. This guide returns a weekday label for readability.