## Converting Date and Time Values

### Use

The sdb.dbapi module implements the functions that are recommended in the Python Database API specifications v2.0 for the conversion of date and time values.

### Features

Converting Python values -> MaxDB values

Function | Return Value
Date (year, month, day) | String that can be used anywhere where the database system expects an input value for an SQL data type DATE
Time (hour, minute, second) | String that can be used anywhere where the database system expects an input value for an SQL data type TIME
Timestamp (year, month, day, hour, minute, second, micros = 0) | String that can be used anywhere where the database system expects an input value for an SQL data type TIMESTAMP
DateFromTicks (ticks) | String that can be used anywhere where the database system expects an input value for an SQL data type DATE
TimeFromTicks (ticks) | String that can be used anywhere where the database system expects an input value for an SQL data type TIME
TimestampFromTicks (ticks) | String that can be used anywhere where the database system expects an input value for an SQL data type TIMESTAMP

Converting MaxDB values -> Python values

Function | Return Value
dateTuple | (year, month, day)
timeTuple | (hour, minute, second)
timestampTuple | Tuple in the same format as the return value for time.localtime ()
dateVal | Number of seconds since epoch
timeVal | Number of seconds since epoch
timestampVal | Number of seconds since epoch
DateFormat (formatString) | Date formatted according to time.strftime
TimeFormat (formatString) | Time formatted according to time.strftime
TimestampFormat (formatString) | Timestamp formatted according to time.strftime

For more information, see the Python documentation at www.python.org.

Registering conversion functions with a cursor or connection object

Callable Object | Description
cursor.setTranslation ([ None, sdb.dbapi.dateTuple, sdb.dbapi.DateFormat('%Y-%m-%d')]) | You transfer a list in which you specify a function for data conversion for every column. If no data conversion is to be performed for a column, then transfer the None object at the position of the column in question.
cursor.setTypeTranslation ({ 'Date': sdb.dbapi.dateTuple, 'Time': sdb.dbapi.timeTuple, 'Fixed':str}) | You transfer a dictionary. As the key you enter the same type name as output by the method sdb.sql.SapDB_ResultSet.getDescription. As values, enter the functions for data conversion. The system uses these functions for all columns of a certain SQL data type.
connection.setTypeTranslation ({ Date': sdb.dbapi.dateTuple, 'Time': sdb.dbapi.timeTuple, 'Fixed':str})‑{}‑ | You transfer a dictionary, that has the same structure as the parameter for cursor.setTypeTranslation. For every newly created Cursor object you call the method setTypeTranslation with the dictionary as parameter.

For more information, see www.python.org.