Current date

3 snippets across 3 stacks - Bash & Linux, Python, SQL

SHBash & Linux

Date & Time

SH · System Info
Syntax
date [+format]
Example
date
date '+%Y-%m-%d %H:%M:%S'
date -d '+7 days' '+%Y-%m-%d'
date -u
Output
Sat Apr  4 14:22:01 UTC 2026
2026-04-04 14:22:01
2026-04-11

Note Common format tokens: %Y (year), %m (month), %d (day), %H (hour), %M (minute), %S (second), %s (Unix epoch). -d adjusts the date (GNU only; on macOS use -v). -u outputs UTC. Useful for timestamped filenames: backup_$(date +%Y%m%d_%H%M%S).tar.gz.

PYPython

datetime Module

PY · Common Standard Library
Syntax
from datetime import datetime, date, timedelta
Example
from datetime import datetime, timedelta

now = datetime.now()
print(now.strftime("%Y-%m-%d %H:%M"))

deadline = now + timedelta(days=7, hours=3)
print(f"Due: {deadline:%B %d, %Y}")

parsed = datetime.strptime("2026-04-04", "%Y-%m-%d")
print(parsed.date())
Output
2026-04-04 14:30
Due: April 11, 2026
2026-04-04

Note For timezone-aware datetimes, use datetime.now(tz=timezone.utc) instead of datetime.utcnow() which is naive and deprecated since 3.12.

SQLSQL

Current Date and Time

SQL · Date Functions
Syntax
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
NOW()
Example
SELECT
  CURRENT_DATE AS today,
  CURRENT_TIMESTAMP AS right_now,
  NOW() AS also_now;
Output
-- today      | right_now                    | also_now
-- 2025-11-20 | 2025-11-20 14:35:22.123456+00 | 2025-11-20 14:35:22.123456+00

Note CURRENT_DATE, CURRENT_TIME, and CURRENT_TIMESTAMP are ANSI standard and work everywhere. NOW() is a function that does the same as CURRENT_TIMESTAMP but is not standard SQL. In a transaction, these return the time the transaction started, not the current wall clock time.

Frequently asked questions

How does Bash & Linux handle current date?
This task is covered in 3 stacks on this page: Bash & Linux, Python, SQL. The "Date & Time" snippet in Bash & Linux uses `date [+format]`.
Which command does the Bash & Linux example use?
The "Date & Time" snippet uses `date [+format]`, from the System Info section of the Bash & Linux cheat sheet.
Which stacks cover "current date" on this page?
Bash & Linux, Python, SQL. Together they hold 3 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Date & Time": Common format tokens: %Y (year), %m (month), %d (day), %H (hour), %M (minute), %S (second), %s (Unix epoch). -d adjusts the date (GNU only; on macOS use -v). -u outputs UTC. Useful for timestamped filenames: backup_$(date +%Y%m%d_%H%M%S).tar.gz.