Batch Timestamp Conversion
Convert thousands of Unix timestamps to human-readable dates (and back) using Bash, Python, and Node.js scripts. Ideal for log analysis, database migrations, and CSV processing.
The Problem
You have a CSV export, database dump, or log file with thousands of Unix timestamps that need converting to human-readable dates — or vice versa. Converting them one at a time in a web tool would take hours.
Why Batch Processing Matters
Batch timestamp conversion is critical for log analysis (converting millions of epoch timestamps in server logs), database migrations between systems that use different date formats, CSV data cleaning for analytics dashboards, and audit trail processing where every record has a Unix timestamp.
Common Use Cases
- Convert Unix timestamps in server logs to human-readable dates for analysis
- Migrate date columns between databases with different timestamp formats
- Process CSV exports where dates are stored as epoch seconds
- Generate test fixtures with realistic timestamp sequences
- Normalize mixed-format date columns (ISO 8601, Unix, RFC 2822) to a single format
Step-by-Step Instructions
Identify timestamp columns
Inspect your data to find which columns contain timestamps. Unix timestamps are typically 10 digits (seconds) or 13 digits (milliseconds). Use head -5 data.csv to preview.
Choose target format
Decide your output format: ISO 8601 (2026-04-10T14:30:00Z), locale-specific (Apr 10, 2026 2:30 PM), or Unix epoch. Use the Timestamp Converter to test a single value first.
Run batch conversion
Use the scripts below to process your entire file. Bash is fastest for simple conversions; Python handles edge cases (timezones, milliseconds) more gracefully.
Validate output
Spot-check converted dates against a known reference. Verify timezone handling: date -d @1712764200 should match your expected local time. Check for off-by-one-hour errors (DST transitions).
Code Examples
# Convert Unix timestamps in column 3 of a CSV to ISO 8601
awk -F',' '{
if (NR == 1) { print; next }
cmd = "date -d @" $3 " -u +%Y-%m-%dT%H:%M:%SZ"
cmd | getline converted; close(cmd)
$3 = converted; print
}' OFS=',' input.csv > output.csv
# Quick: convert a list of timestamps (one per line)
while read ts; do
date -d "@$ts" '+%Y-%m-%d %H:%M:%S %Z'
done < timestamps.txt > dates.txt
# Millisecond timestamps (13 digits) — divide by 1000
awk '{print int($1/1000)}' ms_timestamps.txt | \
while read ts; do date -d "@$ts" -u -Iseconds; done
Single vs Batch Comparison
Paste 1712764200 → see 'Wed Apr 10 2024 14:30:00 UTC'
$ wc -l server_logs.csv 15842 server_logs.csv $ python convert_timestamps.py Converted 15841 timestamps to ISO 8601 $ head -3 data_converted.csv id,event,timestamp,user 1,login,2026-04-10T08:15:30+00:00,alice 2,logout,2026-04-10T09:45:12+00:00,bob
Frequently Asked Questions
How do I tell if a timestamp is in seconds or milliseconds?
Count the digits: 10 digits (e.g., 1712764200) are seconds since epoch, 13 digits (e.g., 1712764200000) are milliseconds. If the number is greater than 1 trillion, divide by 1000 to get seconds.
How do I handle timezone conversions in batch?
Always store and process in UTC first, then convert to local time as the final step. In Python, use datetime.fromtimestamp(ts, tz=timezone.utc). In Bash, add TZ='America/New_York' before the date command.
What about dates before 1970 (negative Unix timestamps)?
Python and Node.js handle negative timestamps natively. Bash date on Linux supports them too. macOS date may not — use gdate from GNU coreutils (brew install coreutils) or Python instead.
Related Batch Guides
Try these tools interactively
Each tool runs in your browser with no signup required. Process single items instantly.