Convert Date to Milliseconds

How would I go about converting the following two dates to milliseconds? I looked at some other examples online but they seem to be pretty complex and I wasn’t able to get it to function correctly:

  1. 01/01/2021
  2. 12/31/2021


Hi @GTowerz

Can you expand a little bit more on what you are trying to achieve? Please include your expected result.

In the interim, I have some options you can use.

Option #1: Use Two Assign Activities and DateTime Variable
Step 1: Convert Input String to a DateTime Variable (System.DateTime) called “Date1”. Then insert an Assign activity.


Step 2: Convert DateTime variable into the desired format. Insert another Assign Activity.

Date1.ToString(“MM/dd/yyyy HH;mm;ss;ffff”)

Replace the text in italics in the above line with your desired format. For a list of the format options see: Date Time format Library in C#.

Option #2: Use one Assign Activity
Use an assign activity like this (noting my time data will not exist)


system.DateTime.ParseExact(INSERTxSTRINGxVALUE, “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture).tostring(“MM/dd/yyyy HH;mm;ss;ffff”)

Note: The first quotation marks MUST match the format of your input string.
Note: The second set of quotation marks is your desired output format. For more format options see: Date Time format Library in C#.

Here is the demo workflow you can download and review.
DateTime Demo.xaml (8.3 KB)


Hopefully this helps you :blush:

1 Like

Hello, thank you for your response. @Steven_McKeering

I need to convert a date value “01/01/2021” into millisecond format.
The API I’m using takes an input parameter (start date) in millisecond format. So I basically need to input start date “01/01/2021” but in milliseconds.

Is this possible to do? Not sure if that’s what the “ffff” is in your reply:

“System.Globalization.CultureInfo.InvariantCulture).tostring(“MM/dd/yyyy HH;mm;ss;ffff”)”

I can’t say I can help then sorry. I’d be keen to understand more because milliseconds (time) is a duration and not the greatest trigger without a date component.

There are 86,400,000 milliseconds in a day.

Is there any documentation you can find?

Date is time point whereas millisecond is duration. You cannot convert time point into millisecond if I did not misunderstand your question. Can you give an example of your expected millisecond format?

@liu_Shubin I found this online in a date to millisecond calculator:

The issue I’m having is that this date/time I’m receiving within my report is coming out in milliseconds…

Wondering if there’s a way within UiPath to change from millisecond format to dateTime and vice versa?

You can refer to the old post on how to convert Excel date value to date string. The solution is applicable to your issue.

Hi @GTowerz ,

According to the website that you have mentioned, the Milliseconds value is actually the Total Milliseconds present between two Dates.

First Date being - Mon Feb 07 2022 17:00:00 GMT-0500

Second Date being the Date Specified in the website i.e start of the Unix Epoch Time
Wed Dec 31 1969 19:00:00 GMT-0500

We can Convert this into the DateTime format first as both are in the same format as mentioned below :

ddd MMM dd yyyy HH':'mm':'ss 'GMT'K

After Converting both the Dates in String format to DateTime formats, we find the Difference between these two dates, and then Calculate the Total Milliseconds between them.

To Convert again from Milliseconds to DateTime format, we could take the Unix Epoch Time again as the Date to be referred to Calculate the Date after the Milliseconds.

This conversion is depended on the Website that you have referred, since the Start Date Time that needs to be compared was provided in it.

Let us know if you are still not able to resolve the issue.

1 Like


And also:
new DateTimeOffset(YourDateTimeVar).ToUnixTimeMilliseconds

as it results to long numbers the ’ trick can help for writing out the milliseconds to excel by forcing it to treat it as text

@ppr It worked thank you! Only additional question is that the datetime → milliseconds worked perfectly, however I seem to be getting an error when attempting to convert from milliseconds to dateTime.


The error reads:
Complier error(s) encountered processing expression “new DateTimeOffset.FromUnixTimeMilliseconds(1644271200000).DateTime”. Type “DateTimeOffset.FromUnixTimeMilliseconds” is not defined.

My DateTime variable is type datetime. Any idea what could be occurring?

taken from DateTimeOffset.FromUnixTimeMilliseconds(Int64) Method (System) | Microsoft Docs

as it is a static method we do not initiate a datetime

Hi @ppr, thank you for you response again. For clarification, how would this be written in UiPath?

I imagine there’s a specific way to write it as this is giving me an error:

same as done within the immediate panel from screenshot above

assign Activity
LHS: yourDateTimeVar | DataType: DateTime
RHS: DateTimeOffset.FromUnixTimeMilliseconds(yourMSVar).DateTime

1 Like

Perfect, thank you again! It worked :grin:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.