Daniel Ferreira
Daniel Ferreira

Reputation: 113

Azure Data Factory Mapping Data Flow: Epoch timestamp to Datetime

I have a JSON-based source I'd like to transform using ADF Mapping Data Flow. I have a string containing an epoch timestamp value that I want to transform to Datetime value to later sink it into Parquet file.

Do you know a way? Docs of this language are here.

Source file:

{
  "timestamp":"1574127407",
  "name":"D.A."
}

Upvotes: 2

Views: 8678

Answers (2)

Sandip Chicholikar
Sandip Chicholikar

Reputation: 1

I have came across various epoch timestamp values which are of 13 digits i.e., they even have milliseconds detailed information.

In such case, converting to integer using 'toInteger' won't serve the purpose instead this will keep the values as NULL. So, to fix this issue, we need to convert it to Long using toLong as below:

toTimestamp(toLong(toString(created)),'yyyy-MM-dd HH:mm:ss')

In above expression, 'created' is a field whose value is 13-digit epoch timestamp, something like this created='1635359043307'.

Here, toTimestamp returns the Date Timestamp with above-mentioned date format.

FYI, you can use this site https://www.epochconverter.com/ to check epoch timestamp to human date.

Upvotes: 0

Mark Kromer MSFT
Mark Kromer MSFT

Reputation: 3838

Use toTimestamp() and set the formatting you wish as 2nd parameter

toTimestamp(1574127407*1000l)

From string:

toTimestamp(toInteger(toString(byName('timestamp')))*1000l,'yyyy-MM-dd HH:mm:ss')

Upvotes: 2

Related Questions