简体   繁体   中英

How to convert db2 date format to H2 date format for in memory testing in java

I am trying to convert the DB2 data base Date field format into H2 in memory database date format as shown below. It did not work for me. Please help.

select CREATE_DATE from PX.MY_DB2TABLE ;

Here DB2 DATE format in database table is 'MM/DD/YYYY'. CREATE_DATE is DATE data type in db2.

H2 database is accepting only 'yyyy-MM-dd' format.

Tried the following way in H2:

  select PARSEDATETIME(CREATE_DATE,'MM/dd/yyyy') FROM PX.MY_DB2TABLE;
    select PARSEDATETIME(CREATE_DATE,'yyyy-MM-dd') FROM PX.MY_DB2TABLE;

Error: Cannot parse DATE constant

To obtain a character-string representation from a DATE data-type value with the format 'YYYY-MM-DD', the DATE field selected in the original query [from the OP] can be wrapped in a CHAR casting scalar with an additional argument requesting that particular date-formatting for the Datetime to character casting; no mention of which variant of DB2, but here is some doc: DB2 for Linux UNIX and Windows 9.7.0->Database fundamentals->SQL->Functions->Scalar functions->CHAR :

select CHAR(CREATE_DATE, ISO) from PX.MY_DB2TABLE ;

For the second argument, see Date Strings Table 1. Formats for String Representations of Dates in [imagining LOCAL as the valid argument, in place of the LOC as seen in the table ]: DB2 for Linux UNIX and Windows 9.7.0->Database fundamentals->SQL->Language elements->Data types->Data type list->Datetime values

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM