How to convert Date.ms to integer

How can the Date.ms object be converted to an integer please.
Trying to measure time to enumerate a collection.

Are you talking about the DO Date object or something else?
Because the DO Date.ms property is already an integer or not?

Can you give a little example?

nvm. found error. this works

    var milliseconds1 = DOpusFactory.Date().ms;
	fileFolderCount.CountItems();
	var milliseconds2 = DOpusFactory.Date().ms;
	log(milliseconds2 - milliseconds1);

That's not the right way to compare two times. You're only comparing the milliseconds component of each time.

(It's like comparing only the minutes part of 10:50 and 11:05, which would give you -45 instead of the 15 you probably expect.)

The Data object has Add and Sub methods for calculating the sum or difference of two dates.

You could do it like this:

many thanks all. Very useful.

getting undefined when trying to us Date().Sub()

var milliseconds1 = DOpusFactory.Date();
DOpus.Delay(100);
var milliseconds2 = DOpusFactory.Date();

var diff = milliseconds2.Sub(milliseconds1.ms, 'l');

DOpus.Output(diff);

Doing this doesn't work?

var ini= new Date();
//do something
log(new Date() - ini);

was trying to get the inbuilt method to work. Normal subtractions do work though;

Is there something like this available, (milliseconds elapsed from anchor date). Which I think the Add() and Sub() methods might be using ??

The getTime() method of Date instances returns the number of milliseconds for this date since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC .

Almost, and lxp already give you a hint before.

Hmmm, thats great and many thanks for all assists, but that is still not using the Add() and Sub() methods. Are they buggy ?

Both modify objects, they don't return anything.

We'll be adding a few more date and timer helpers to the scripting API in 13.2.1 (first beta after 13.2 goes out). They should make doing everything in this thread a lot easier.

1 Like

image

Really needs to be int64 or uint64
it won't even display anchor date using

var date = DOpus.Create.Date();
date.Sub(date + date.ms, 'l');
DOpus.Output(date.day + ' - ' + date.month + ' - ' + date.year);

date.Sub(2147483647, 'l'); works (takes about month off)
date.Sub(2147483648, 'l'); (+1) does not work

In 13.4.4, Date.Add and Sub will accept up to 64-bit signed numbers.