Use when files need timestamps, APIs need dates, or user asks for current date/time
This skill provides the current date and time in 8 essential formats through a single command. It outputs standardized timestamps suitable for various use cases including file naming, API queries, database operations, logging, and user-facing displays.
All outputs follow industry standards (ISO 8601, Unix epoch) and are provided as KEY=VALUE pairs for easy integration into shell scripts, automation workflows, and AI agent operations.
Use this skill whenever you need:
Run the script to get all date/time formats at once:
./scripts/datetime.sh
Example output:
DATE_ISO=2026-01-19
DATETIME_ISO=2026-01-19T14:30:05+08:00
DATETIME_UTC=2026-01-19T06:30:05Z
TIMESTAMP_UNIX=1768918205
DATE_HUMAN=January 19, 2026
DATETIME_FILE=20260119-143005
DATE_COMPACT=20260119
TIMEZONE=+08:00
To use the values in your script:
eval "$(./scripts/datetime.sh)"
echo "Today is $DATE_ISO"
echo "Timestamp: $TIMESTAMP_UNIX"
| Variable | Format | Example | Primary Use Cases |
|---|---|---|---|
DATE_ISO | YYYY-MM-DD | 2026-01-19 | Standard date for databases, APIs, sorting |
DATETIME_ISO | YYYY-MM-DDTHH:MM:SS±HH:MM | 2026-01-19T14:30:05+08:00 | Precise timestamp with timezone for APIs, logs |
DATETIME_UTC | YYYY-MM-DDTHH:MM:SSZ | 2026-01-19T06:30:05Z | UTC format for distributed systems |
TIMESTAMP_UNIX | Seconds since epoch | 1768918205 | API timestamps, time calculations |
DATE_HUMAN | Month DD, YYYY | January 19, 2026 | User-facing displays, reports |
DATETIME_FILE | YYYYMMDD-HHMMSS | 20260119-143005 | Filenames, backup files, no special chars |
DATE_COMPACT | YYYYMMDD | 20260119 | Short filenames, database keys |
TIMEZONE | ±HH:MM | +08:00 | Timezone offset awareness |
All timestamps reflect the system's local timezone unless explicitly noted as UTC.
Create files with timestamps in their names for easy sorting and identification:
# Load all date/time variables
eval "$(./scripts/datetime.sh)"
# Create a timestamped backup
cp database.db "backups/database-${DATE_ISO}.db"
# Create a log file with full timestamp
touch "logs/app-${DATETIME_FILE}.log"
# Generate a report with human-readable date
echo "Sales Report for $DATE_HUMAN" > "reports/sales-${DATE_COMPACT}.txt"
Pass properly formatted dates to REST APIs:
# Get date variables
eval "$(./scripts/datetime.sh)"
# Query an API with ISO date
curl "https://api.example.com/events?date=${DATE_ISO}"
# Send JSON with ISO datetime and timezone
curl -X POST https://api.example.com/logs \
-H "Content-Type: application/json" \
-d "{\"timestamp\": \"${DATETIME_ISO}\", \"message\": \"System check\"}"
# Use Unix timestamp for time-based APIs
curl "https://api.example.com/data?since=${TIMESTAMP_UNIX}"
Embed timestamps in JSON, CSV, or other structured formats:
eval "$(./scripts/datetime.sh)"
# Create JSON with multiple timestamp formats
cat > event.json <<EOF
{
"event_id": "evt_${TIMESTAMP_UNIX}",
"created_at": "${DATETIME_ISO}",
"created_at_utc": "${DATETIME_UTC}",
"date": "${DATE_ISO}",
"display_date": "${DATE_HUMAN}",
"timezone": "${TIMEZONE}"
}
EOF
# Append to CSV log
echo "${DATE_ISO},${TIMESTAMP_UNIX},system_check,OK" >> system_log.csv
Create daily or periodic backups with organized naming:
#!/usr/bin/env bash
# Daily backup script
eval "$(./scripts/datetime.sh)"
# Define backup directory with date
BACKUP_DIR="backups/${DATE_ISO}"
mkdir -p "$BACKUP_DIR"
# Backup files with timestamps
tar -czf "${BACKUP_DIR}/data-${DATETIME_FILE}.tar.gz" /path/to/data
tar -czf "${BACKUP_DIR}/config-${DATETIME_FILE}.tar.gz" /etc/myapp
# Log the backup
echo "[${DATETIME_ISO}] Backup completed successfully" >> backup.log
# Cleanup old backups (keep last 7 days)
find backups/ -type d -mtime +7 -exec rm -rf {} +
Create and append to timestamped log files:
eval "$(./scripts/datetime.sh)"
# Create daily log file
LOGFILE="logs/app-${DATE_COMPACT}.log"
# Append entries with ISO timestamps
echo "[${DATETIME_ISO}] Application started" >> "$LOGFILE"
echo "[${DATETIME_ISO}] Connected to database" >> "$LOGFILE"
# Create a log entry function
log_message() {
eval "$(./scripts/datetime.sh)"
echo "[${DATETIME_ISO}] $1" >> "$LOGFILE"
}
log_message "Processing batch job"
log_message "Batch job completed"
Use timestamps for scheduling decisions and time-based logic:
eval "$(./scripts/datetime.sh)"
# Check if it's time for maintenance (compare Unix timestamps)
LAST_MAINTENANCE=$(cat last_maintenance.txt)
TIME_SINCE=$((TIMESTAMP_UNIX - LAST_MAINTENANCE))
TWENTY_FOUR_HOURS=86400
if [ $TIME_SINCE -ge $TWENTY_FOUR_HOURS ]; then
echo "Running maintenance..."
./maintenance.sh
echo "$TIMESTAMP_UNIX" > last_maintenance.txt
fi
# Create time-based directory structure
ARCHIVE_DIR="archives/${DATE_ISO:0:4}/${DATE_ISO:5:2}" # YYYY/MM
mkdir -p "$ARCHIVE_DIR"
mv processed_*.dat "$ARCHIVE_DIR/"
DATE_ISO for simple dates, database date fields, and when you don't need time informationDATETIME_ISO when you need precise timestamps with timezone awareness (most common for logging)DATETIME_UTC for distributed systems, international applications, or when coordinating across timezonesTIMESTAMP_UNIX for time calculations, sorting by time, or APIs that expect Unix timestampsDATE_HUMAN only for user-facing output, never for file names or database storageDATETIME_FILE for file and directory names (no colons or spaces, safe on all platforms)DATE_COMPACT when you need short date identifiers or daily groupingDATETIME_UTC reflect your system's local timezoneTIMEZONE variable shows your current offset from UTCDATETIME_UTC when storing timestamps that will be accessed from multiple timezones# Pattern 1: Load once, use multiple times
eval "$(./scripts/datetime.sh)"
process_data "$DATE_ISO"
create_backup "$DATETIME_FILE"
log_event "$DATETIME_ISO"
# Pattern 2: Inline for simple cases
BACKUP_FILE="backup-$(./scripts/datetime.sh | grep DATE_ISO | cut -d= -f2).tar.gz"
# Pattern 3: Source in functions
get_timestamp() {
eval "$(./scripts/datetime.sh)"
echo "$DATETIME_ISO"
}
If you get a "Permission denied" error:
chmod +x ./scripts/datetime.sh
If running from a different directory:
# Use absolute path
eval "$(/absolute/path/to/scripts/datetime.sh)"
# Or change to skill directory first
cd /path/to/current-date-and-time-skill
eval "$(./scripts/datetime.sh)"
This script is compatible with both BSD date (macOS) and GNU date (Linux). If you experience issues:
If timezone appears without colon (e.g., +0800 instead of +08:00):
This shouldn't happen with the current script, but if you see it, ensure the sed command is working:
date '+%z' | sed -E 's/([+-][0-9]{2})([0-9]{2})$/\1:\2/'
If variables are empty after eval:
# Check script output directly
./scripts/datetime.sh
# Verify eval syntax (note the double quotes and dollar-parentheses)
eval "$(./scripts/datetime.sh)"
# Check if variables are set
echo "DATE_ISO is: ${DATE_ISO:-NOT SET}"
The script uses your system time. To verify:
# Check system time
date
# Check timezone setting
date +%Z
# For UTC time specifically
date -u
#!/usr/bin/env bash
set -euo pipefail
# Load datetime variables
eval "$(./scripts/datetime.sh)"
# Configuration
SOURCE_DIR="/var/www/html"
BACKUP_ROOT="/backups"
BACKUP_DIR="${BACKUP_ROOT}/${DATE_ISO}"
LOGFILE="${BACKUP_ROOT}/backup.log"
# Create backup directory
mkdir -p "$BACKUP_DIR"
# Create backup with timestamp
BACKUP_FILE="${BACKUP_DIR}/website-${DATETIME_FILE}.tar.gz"
tar -czf "$BACKUP_FILE" "$SOURCE_DIR"
# Log success
echo "[${DATETIME_ISO}] Backup created: ${BACKUP_FILE}" >> "$LOGFILE"
# Cleanup old backups (keep 30 days)
find "$BACKUP_ROOT" -type f -name "*.tar.gz" -mtime +30 -delete
echo "Backup completed: $BACKUP_FILE"
#!/usr/bin/env bash
# Load datetime variables
eval "$(./scripts/datetime.sh)"
# API configuration
API_URL="https://api.example.com/metrics"
API_KEY="your-api-key"
# Send metrics with timestamp
curl -X POST "$API_URL" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"timestamp\": \"${DATETIME_ISO}\",
\"timestamp_unix\": ${TIMESTAMP_UNIX},
\"metric\": \"cpu_usage\",
\"value\": 45.2,
\"timezone\": \"${TIMEZONE}\"
}"
MIT License - See LICENSE.txt for details.
1.0.0 - Initial release with 8 essential date/time formats