Skip to main content

Module time

Module time 

Source
Expand description

Time Format Mapping for cross-dialect transpilation.

This module handles conversion of date/time format specifiers between different SQL dialects. Each dialect has its own conventions for formatting dates and times:

  • strftime (Python, SQLite): %Y, %m, %d, %H, %M, %S
  • MySQL: %Y, %m, %d, %H, %i, %s
  • PostgreSQL/Oracle: YYYY, MM, DD, HH24, MI, SS
  • BigQuery: strftime-like (%Y, %m, %d, %H, %M, %S)
  • Snowflake: YYYY, MM, DD, HH24, MI, SS, FF
  • Spark/Hive: Java DateTimeFormatter (yyyy, MM, dd, HH, mm, ss)
  • T-SQL: Primarily uses numeric style codes (120, 121, etc.)

§Example

use sqlglot_rust::dialects::time::{format_time, TimeFormatStyle};

// Convert MySQL format to PostgreSQL format
let pg_format = format_time("%Y-%m-%d %H:%i:%s",
    TimeFormatStyle::Mysql,
    TimeFormatStyle::Postgres);
assert_eq!(pg_format, "YYYY-MM-DD HH24:MI:SS");

Structs§

FormatConversionResult
Result of a format conversion that may include warnings.

Enums§

TimeFormatStyle
Time format styles used by different dialect families.
TsqlStyleCode
T-SQL date/time style codes used with CONVERT function.

Functions§

format_time
Convert a time format string from one dialect style to another.
format_time_dialect
Convert a time format string from one SQL dialect to another.
format_time_with_warnings
Convert a time format string with warning collection.