SQLDateTime[datetime]
represents date and time information that can be stored in a database.
Details and Options
Examples
Basic Examples
Generalizations & Extensions
See Also
Tech Notes
Related Guides
DatabaseLink`
DatabaseLink`
SQLDateTime
SQLDateTime[datetime]
represents date and time information that can be stored in a database.
Details and Options
- To use SQLDateTime, you first need to load DatabaseLink using Needs["DatabaseLink`"].
Examples
open all close allBasic Examples (1)
Needs["DatabaseLink`"]If you find that the examples in this section do not work as shown, you may need to install or restore the example database with the DatabaseLink`DatabaseExamples` package, as described in Using the Example Databases.
conn = OpenSQLConnection[JDBC["H2(Memory)", "sandbox"]];This creates a table with data types DATE, DATETIME, and TIMESTAMP:
SQLCreateTable[conn, SQLTable["DATETIMETABLE"], {SQLColumn["DATECOL", "DataTypeName" -> "DATE"], SQLColumn["DATETIMECOL", "DataTypeName" -> "DATETIME"], SQLColumn["TIMESTAMPCOL", "DataTypeName" -> "TIMESTAMP"]}]This inserts the same data into each column:
With[{d = SQLDateTime[DateList[]]}, SQLInsert[conn, "DATETIMETABLE", {"DATECOL", "DATETIMECOL", "TIMESTAMPCOL"},
{d, d, d}]
]This selects the data as stored in the database:
SQLSelect[conn, "DATETIMETABLE"]//First//ColumnThis creates a table with data type TIME:
SQLCreateTable[conn, SQLTable["TIMETABLE"], {SQLColumn["TIMECOL", "DataTypeName" -> "TIME"]}]SQLInsert[conn, "TIMETABLE", {"TIMECOL"}, {SQLDateTime[Round[Take[DateList[], -3]]]}]SQLSelect[conn, "TIMETABLE"]//First//ColumnSQLDropTable[conn, "TIMETABLE"];SQLDropTable[conn, "DATETIMETABLE"];CloseSQLConnection[conn];Generalizations & Extensions (1)
Needs["DatabaseLink`"]conn = OpenSQLConnection[JDBC["H2(Memory)", "sandbox"]];SQLDateTime expressions may be padded as necessary:
SQLExecute[conn, "SELECT ?", {SQLDateTime[{2014, 2, 1}]}]SQLExecute[conn, "SELECT ?", {SQLDateTime[{0, 1, 2}]}]CloseSQLConnection[conn];