Skip to main content

Date & Time Format Directives

These directives are commonly used in tools like date, logging systems, and programming languages to format timestamps.

Directives

DirectiveRepresentsExample
%Y4-digit year2026
%mMonth01-12
%dDay of month01-31
%HHour (24-hour format)00-23
%MMinute00-59
%SSecond00-59

Example Format

%Y-%m-%d %H:%M:%S
Example output:
2026-03-06 14:25:10

Example in Shell

date "+%Y-%m-%d %H:%M:%S"
Output:
2026-03-06 14:25:10

Example for File Names

backup-%Y-%m-%d-%H-%M-%S.sql
Example result:
backup-2026-03-06-14-25-10.sql

Common Patterns

PatternExampleUse
%Y-%m-%d2026-03-06Date only
%Y%m%d20260306Compact date
%Y-%m-%d %H:%M:%S2026-03-06 14:25:10Logs
%Y%m%d-%H%M%S20260306-142510Filenames