690
Views
8
Comments
Solved
Is there a function that can convert milliseconds to datetime?
Question

I want to convert Milliseconds to DateTime how can I do this?

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Halit,

There's no such Action available out of the box. However, if you have the offset of the milliseconds, e.g. 1970-01-01, you could use the built-in AddSeconds Function like this:

AddSeconds(#1970-01-01#, MilliSeconds / 1000)


2019-09-25 11-58-19
Halit Ozdogru

Kilian Hekhuis wrote:

Hi Halit,

There's no such Action available out of the box. However, if you have the offset of the milliseconds, e.g. 1970-01-01, you could use the built-in AddSeconds Function like this:

AddSeconds(#1970-01-01#, MilliSeconds / 1000)


I use it like this: 

SyntaxEditor Code Snippet

AddSeconds(DurationTable.List.Current.Duration.SpanStart, DurationTable.List.Current.Duration.Duration / 1000)

the spanstart is an datetime and it saves the date when the duration is saved in DB. The duration is an long integer and it gives the duration in milliseconds. If I use youre function I just get: 08-10-2019 21:13:09 but I want the calculation between mine spanStart and SpanEnd and show it in Time or DateTime


2019-09-25 11-58-19
Halit Ozdogru

Kilian Hekhuis wrote:

Hi Halit,

There's no such Action available out of the box. However, if you have the offset of the milliseconds, e.g. 1970-01-01, you could use the built-in AddSeconds Function like this:

AddSeconds(#1970-01-01#, MilliSeconds / 1000)


Thank You it worked for me instead of span start I needed to set NullDate()


2020-02-15 02-48-12
Galter
Champion

Kilian Hekhuis wrote:

Hi Halit,

There's no such Action available out of the box. However, if you have the offset of the milliseconds, e.g. 1970-01-01, you could use the built-in AddSeconds Function like this:

AddSeconds(#1970-01-01#, MilliSeconds / 1000)


Thanks, it helped me a lot in a conversion

2022-05-06 16-37-40
Joseph Danne Enriquez

Hi Halit!

You could convert the milliseconds into seconds into bigger time units like seconds, minutes, hours, days or even years using an Assign variable. Convert it to Text data type then use the appropriate built-in DataConversion functions.

Reference:
https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Logic/Built-in_Functions/Data_Conversion

Kind regards,
Joseph Enriquez

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

@Joseph: I already gave Halit the solution. Converting anything to Text and back just for conversion is always bad practice, but in this case I can't see how it would help at all.

2022-05-06 16-37-40
Joseph Danne Enriquez

Kilian Hekhuis wrote:

@Joseph: I already gave Halit the solution. Converting anything to Text and back just for conversion is always bad practice, but in this case I can't see how it would help at all.

Hi Kilian!

I wasn't refreshing the Forums while I was typing out my reply to Halit's question. My apologies.

Kind regards,
Joseph Enriquez


2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Halit,

That seems to make sense :). Glad I could be of help!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.