Extract Date and Timestamp Columns from SQL

Convert SQL DATE, DATETIME, TIMESTAMP, and TIME columns to CSV. Date values are preserved in their original format from the INSERT statements.

Data Types

Detailed Explanation

Dates and Timestamps in SQL to CSV

Date and time values in SQL come in many formats: DATE, DATETIME, TIMESTAMP, TIMESTAMP WITH TIME ZONE, and TIME. Since these are stored as quoted strings in INSERT statements, they are extracted and included in the CSV exactly as written.

Example SQL

CREATE TABLE events (
  id INTEGER PRIMARY KEY,
  event_name VARCHAR(200),
  event_date DATE,
  start_time TIMESTAMP,
  end_time TIMESTAMP,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO events VALUES
  (1, 'Product Launch', '2024-03-15', '2024-03-15 09:00:00', '2024-03-15 17:00:00', '2024-01-10 14:23:45'),
  (2, 'Team Offsite', '2024-04-20', '2024-04-20 08:30:00', '2024-04-22 16:00:00', '2024-02-01 09:15:00'),
  (3, 'Quarterly Review', '2024-06-30', '2024-06-30 14:00:00', '2024-06-30 16:30:00', '2024-03-15 11:00:00');

Generated CSV

id,event_name,event_date,start_time,end_time,created_at
1,Product Launch,2024-03-15,2024-03-15 09:00:00,2024-03-15 17:00:00,2024-01-10 14:23:45
2,Team Offsite,2024-04-20,2024-04-20 08:30:00,2024-04-22 16:00:00,2024-02-01 09:15:00
3,Quarterly Review,2024-06-30,2024-06-30 14:00:00,2024-06-30 16:30:00,2024-03-15 11:00:00

Format Preservation

The tool preserves date formats exactly as they appear in the SQL:

  • '2024-03-15' stays as 2024-03-15
  • '2024-03-15 09:00:00' stays as 2024-03-15 09:00:00
  • '2024-03-15T09:00:00Z' stays as 2024-03-15T09:00:00Z (ISO 8601)
  • '2024-03-15 09:00:00+05:30' stays as 2024-03-15 09:00:00+05:30 (with timezone)

No date parsing or reformatting is performed. This ensures lossless conversion and avoids timezone or locale-specific interpretation issues.

Importing into Spreadsheets

When opening the CSV in Excel or Google Sheets, date columns may be auto-detected and reformatted according to your locale settings. To preserve the exact format, import as text or use the "Text to Columns" feature with explicit column types.

Use Case

Extracting event schedules, audit logs, or transaction histories from SQL dumps where preserving exact timestamp formats is critical for downstream processing.

Try It — SQL to CSV Converter

Open full tool