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
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
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-DDYYYY-MM-DD HH:MMYYYY-MM-DD HH:MM:SSYYYY-MM-DD HH:MM:SS.SSSYYYY-MM-DDTHH:MMand 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
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
A KQLiteColumn containing the date part (e.g., in YYYY-MM-DD format).
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
A KQLiteColumn containing a date/time value or the result of a date/time modification.