How to Work with UTC Timestamps in Azure Data Factory

DataCoder 280 Reputation points
2024-08-13T18:00:28.16+00:00

I need assistance in writing a Data Flow expression in Azure Data Factory to generate the current UTC timestamp in the format yyyy-MM-ddTHH:mm:ss.SSS. Additionally, I would like to understand how to create expressions that allow me to both subtract and add a specific duration (e.g., days, hours, minutes, etc.) to this timestamp. Could you provide guidance or examples on how to accomplish this within Azure Data Factory's Data Flow?

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

Accepted answer
  1. NIKHILA NETHIKUNTA 4,600 Reputation points Microsoft External Staff
    2024-08-14T07:29:15.8033333+00:00

    Hi @DataCoder
    Thank you for your question and using the Microsoft Q&A platform.
    To generate the current UTC timestamp in the format yyyy-MM-ddTHH:mm:ss.SSS, you can use the following expression in a Derived Column transformation in Azure Data Factory's Data Flow:

    toTimestamp(toUtc(now()), "yyyy-MM-dd'T'HH:mm:ss.SSS")
    

    This expression uses the now() function to get the current UTC timestamp, then converts it to a UTC timestamp using the toUtc() function, and finally formats it using the toTimestamp() function with the specified format string.

    To add or subtract a specific duration (e.g., days, hours, minutes, etc.) to this timestamp, you can use the addDuration() or subtractDuration() functions in a Derived Column transformation. Here are some examples:

    To add 1 day to the current UTC timestamp:

    addDuration(toTimestamp(toUtc(now()), "yyyy-MM-dd'T'HH:mm:ss.SSS"), duration('P1D'))
    

    To subtract 1 hour from the current UTC timestamp:

    subtractDuration(toTimestamp(toUtc(now()), "yyyy-MM-dd'T'HH:mm:ss.SSS"), duration('PT1H'))
    
    

    These expressions will help you generate and manipulate timestamps as needed in your Data Flow.

    Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.