Provides a java.sql.Date object wrapper that can be used as date type for database operations. It extends Ax.util.Date so you an refer to Ax.util.Date for a complete description.
1 Database date format
Dates can be passed as arguments for arguments used in the prepared statement. But connot be prepared in the columns section of statement.
By default, date toString
returns the Java date
representation so we can not use it as a valid date literal for a SQL statement.
You can create a date passing it a database connection. In that case, the toString
method will return the database date function for the date object.
Let's see some examples (notice you need to use a stirng template to resolve date variable):
Informix
<script> var current = new Ax.sql.Date(); // Setup the database type for DATE toString() representation current.setConnection(Ax.db); var rs = Ax.db.executeQuery(`SELECT ${current} FROM sysmaster:sysdual`); console.log(rs); console.log(`${current}`); </script>
+----------+
|(constant)|
+----------+
|2019-02-11|
+----------+
MDY(2,11,2019)
Oracle
<script> var current = new Ax.sql.Date(Ax.db); // Setup the database type for DATE toString() representation current.setConnection(Ax.db); var rs = Ax.db.executeQuery(`SELECT ${current} FROM dual`); console.log(rs); console.log(`${current}`); </script>
+----------------------------+
|TO_DATE(20190211,'YYYYMMDD')|
+----------------------------+
|2019-02-11T00:00:00 |
+----------------------------+
TO_DATE(20190211, 'yyyymmdd')