DATETIME

The DATETIME() function returns the date and time as text in this format: YYYY-MM-DD HH:MM:SS.

This overload accepts a Unix epoch timestamp. The Unix epoch is the number of seconds since 1970-01-01 00:00:00 UTC. The function converts this timestamp into a full date and time string.

Example

// SELECT DATETIME(1761301829, 'unixepoch')
select(DATETIME(1761301829).unixepoch()).execute() // Result: "2025-10-24 10:30:29"

Return

A KQLiteColumn of type KQLiteDateTime representing the YYYY-MM-DD HH:MM:SS dateTime.

Author

MOHAMMAD AZIM ANSARI

Parameters

unixepoch

A Long representing the Unix epoch timestamp.

See also


The DATETIME() function returns the date and time as text in this format: YYYY-MM-DD HH:MM:SS.

This overload accepts a Julian day number. A Julian day is the number of days since noon in Greenwich on November 24, 4714BC. The function converts this value into a full date and time string.

Example

// SELECT DATETIME(2460434.937847222)
select(DATETIME(2460434.937847222)).execute() // Result: "2024-05-04 10:30:30"

Return

A KQLiteColumn of type KQLiteDateTime representing the YYYY-MM-DD HH:MM:SS dateTime.

Author

MOHAMMAD AZIM ANSARI

Parameters

julianday

A Double representing the Julian day number.

See also


The DATETIME() function returns the date and time as text in this format: YYYY-MM-DD HH:MM:SS.

This overload accepts a dateTime string. The dateTime string can be in various formats recognized by SQLite, such as:

  • YYYY-MM-DD

  • YYYY-MM-DD HH:MM

  • YYYY-MM-DD HH:MM:SS

  • YYYY-MM-DD HH:MM:SS.SSS

  • YYYY-MM-DDTHH:MM

  • and others, including 'now', 'start of month', etc.

The function will format the input into a standard YYYY-MM-DD HH:MM:SS string.

Example

// SELECT DATETIME('2024-05-04 10:30')
select(DATETIME("2024-05-04 10:30")).execute() // Result: "2024-05-04 10:30:00"

// SELECT DATETIME('now')
select(DATETIME("now")).execute() // Result: current date and time

// Applying a modifier
// SELECT DATETIME('now', 'localtime', '+5 hours')
select(DATETIME("now").localtime().hours(5)).execute()

Return

A KQLiteColumn of type KQLiteDateTime representing the YYYY-MM-DD HH:MM:SS dateTime. The result can be null if the input string is not a recognized time string.

Author

MOHAMMAD AZIM ANSARI

Parameters

dateTime

A String representing the date and/or time.

See also


The DATETIME() function returns the date and time as text in this format: YYYY-MM-DD HH:MM:SS.

This overload combines separate date and time columns into a single dateTime string. It first concatenates the date and time columns and then uses the DATETIME() function to ensure proper formatting.

Example

// Assuming a table 'Events' with 'eventDate' (YYYY-MM-DD) and 'eventTime' (HH:MM:SS) columns.
val eventDate = dateColumn("eventDate")
val eventTime = timeColumn("eventTime")

Events
.select(DATETIME(Events.eventDate, Events.eventTime))
.execute()

// If time is omitted, it processes just the date part.
// SELECT DATETIME(eventDate) FROM Events;
Events
.select(DATETIME(Events.eventDate))
.execute()

Return

A KQLiteColumn of type KQLiteDateTime representing the combined YYYY-MM-DD HH:MM:SS dateTime.

Author

MOHAMMAD AZIM ANSARI

Parameters

date

A KQLiteColumn containing the date part (e.g., in YYYY-MM-DD format).

time

An optional KQLiteColumn containing the time part (e.g., in HH:MM:SS format). If null, the time will be treated as 00:00:00.

See also


The DATETIME() function returns the date and time as text in this format: YYYY-MM-DD HH:MM:SS.

This overload accepts a KQLiteColumn that contains a time string, a numeric value (like a Julian day number or Unix epoch time), or the result of a date/time modification. This is particularly useful for applying the DATETIME() function to a table column or a chain of modifier functions.

Example

// Inside KQLiteTable
val loginTime = dateTimeColumn("LoginTime") // Column stores "2024-05-04 10:30:00"

// SELECT DATETIME(LoginTime) FROM Users;
Users
.select(DATETIME(Users.loginTime))
.execute() // Result: "2024-05-04 10:30:00"

Return

A KQLiteColumn of type KQLiteDateTime representing the YYYY-MM-DD HH:MM:SS dateTime.

Author

MOHAMMAD AZIM ANSARI

Parameters

column

A KQLiteColumn containing a date/time value or the result of a date/time modification.

See also