In Azure Data Factory, how can I format a timestamp to current millis?

Angelo Mariano 25 Reputation points
2025-01-20T14:18:44.18+00:00

I am currently trying to get a variable set up as current millis for an API query that only accepts current millis as a valid time filter.

I would like to be able to convert variables such as @utcNow or @pipeline.TriggerTime into current millis, with the example format as follows:

Current Millis: 1737381156710

UTC Time: Mon Jan 20 2025 13:52:36.710

Is there a built in function to do so, or would I have to concatenate several formatDateTime functions?

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

Accepted answer
  1. Sina Salam 22,031 Reputation points Volunteer Moderator
    2025-01-21T13:39:33.5266667+00:00

    Hello Angelo Mariano,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you are in need of how you can format a timestamp to current millis In Azure Data Factory.

    @Ganesh Gurram explains how to compute the current time in milliseconds since the Unix epoch by using ADF expressions. Should there be need for more clarification and explicitly includes handling for @pipeline().TriggerTime, here you go:

    To compute the current time in milliseconds since the Unix epoch (current millis) in Azure Data Factory, you can use the following expression:

    1. Using utcNow():
         @div(sub(ticks(utcNow()), ticks('1970-01-01T00:00:00Z')), 10000)
      
    2. Using @pipeline().TriggerTime:
         @div(sub(ticks(pipeline().TriggerTime), ticks('1970-01-01T00:00:00Z')), 10000)
      
     // Convert the trigger time to ticks
        @ticks(pipeline().TriggerTime)
    
     // Convert ticks to milliseconds
       @div(ticks(pipeline().TriggerTime), 10000)
    
     // Combine the steps into a single expression
       @div(ticks(pipeline().TriggerTime), 10000)
       
    

    Those expressions will give you the current time in milliseconds, which you can use for your API query.

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Ganesh Gurram 7,295 Reputation points Microsoft External Staff Moderator
    2025-01-20T17:31:59.3533333+00:00

    Hi @Angelo Mariano
    Greetings & Welcome to the Microsoft Q&A forum! Thank you for posting your query. 

    Unfortunately, there isn't a direct function to get the current time in milliseconds, but you can achieve this by calculating the difference between the current time and the Unix epoch (January 1, 1970) and then converting that to milliseconds.

    To get the current time in milliseconds since January 1, 1970, the approach is as follows:

    utcnow() - This function gives the current UTC time.

    ticks() - This function gives the number of 100-nanosecond intervals that have passed since 01 January 0001.

    Subtraction of Ticks from Epoch - To convert this to milliseconds since Unix epoch (1970-01-01), subtract the ticks for the Unix epoch from the current ticks.

    Division by 10,000 - Since each tick is 100 nanoseconds, dividing by 10,000 converts it to milliseconds.

    Here’s the expression to calculate milliseconds since the Unix epoch:

    @div(sub(ticks(utcnow()), ticks('1970-01-01T00:00:00Z')), 10000)
    

    This will give you the current time in milliseconds since the Unix epoch, which you can use for your API query.

    Refer to this similar thread in MS Q&A forum: https://learn.microsoft.com/en-us/answers/questions/1273471/azure-logic-apps

    For more details refer to this documentation: https://learn.microsoft.com/en-us/azure/data-factory/control-flow-expression-language-functions#div
    I hope this information helps.  
    Kindly consider upvoting the comment if the information provided is helpful. This can assist other community members in resolving similar issues.

    1 person found this answer helpful.
    0 comments No comments

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.