Extracting Time from Timestamp in ADF

Poel van der, RE (Ron) 451 Reputation points
2022-04-06T13:33:51.817+00:00

Hi

In my source table in SQLDB I have a field, PREANC_DTS datetime2(7)
Example : 2022-03-16 11:56:12.0000000

I want to split the datetime field in a date and time field: PREANC_DT (datatype date) and PREANC_TM (datatype time(7)).
In ADF expression builder this works for PREANC_DT:
iif(isNull(ROK_SLBD_PREANC_DTS),toDate('0001-01-01'),toDate(toString(ROK_SLBD_PREANC_DTS, 'yyyy-MM-dd')))

For PREANC_TM I can get it working , although I tried many things. As you can see I het the time portion, but the output field PREANC_TM becomes a String.
Throughout the data flow the fields keep the right time value, but in the end, in the sink, all those fields become NULL. The pipeline fails and says: PREANC_TM can't be NULL.
I think it happens because the Sink expects a time(7) field and not a string. How to solve and why is there not just a simple toTime function or whatever? :(

190586-knipsel.jpg

Hope someone can help. Thnx a lot
Ron

@MarkKromer-MSFT
@ShaikMaheer-MSFT

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,625 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2022-04-06T14:02:58.827+00:00

    I cannot easily test this but consider using toDate on the base column to get the date portion and then toTimestamp on the base column to get the timestamp. You shouldn't need to parse the string yourself.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.