Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3523

Transforming an ISO 8601 timestamp in HANA

$
0
0

While working on a flow to transform a date in the ISO 8601 format into a HANA TIMESTAMP, I'm getting unexpected results.  A typical input row contains '2016-01-19T06:07:08.473Z' as EncounterDate (there are also instances that do not contain fractional seconds).

 

First of all, the timestamp format 'YYYY-MM-DDTHH24:MI:SS.FF3' isn't accepted by to_timestamp() function, with the 'T' separator not being recognized, nor is the zone adjustment (e.g. 'Z') following the seconds and fraction.   So, after trimming of the last character of the NVARCHAR string, and doing a replace() of the 'T' with a space, this error occurs:

 

SQL:  select to_timestamp(replace(left("EncounterDate", length("EncounterDate")-1),'T', ' ')) as "Encounter_DTM"  from xxx;

 

Error:  Could not execute 'select to_timestamp(replace(left("EncounterDate", length("EncounterDate")-1),'T', ' ')) as ...' in 218 ms 354 µs .

[303]: invalid DATE, TIME or TIMESTAMP value: search table error:  [6931] attribute value is not a date or wrong syntax;longdate [here]longdate(string fox_replace(string midstru(string "EncounterDate", int '1', int sqladd(int chars(string "EncounterDate"), int '-1')), string 'T', string ' ')),EncounterDate = '68788986903'[string]; checkNull false

 

 

However, changing to a substr_before() corrects the remove-last-character issue, but not the 'T' one, so a replace() is still needed:

 

SQL:  select to_timestamp(replace(substr_before("EncounterDate",'Z'), 'T',' ')) as "Encounter_DTM"  from xxx;

 

This seems like a length() issue, but the input column does not contain multi-byte characters.  There also seem to be some intermediate conversions going on, as that value "68788986903" for EncounterDate noted in the error does not appear in the input column.

 

HANA is SPS09, Studio at Patch 97.

 

Has this error been encountered before?  Is there an ISO 8601 date format function in the works?

 

Much Thanks,

  Donn


Viewing all articles
Browse latest Browse all 3523

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>