# How to convert Date.ms to integer

**URL:** <https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743>\
**Category:** Help & Support\
**Created:** [February 7, 2024, 6:28pm UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743 "2024-02-07T18:28:21Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![galaxyhub](https://resource.dopus.com/user_avatar/resource.dopus.com/galaxyhub/32/42793_2.png) [@galaxyhub](https://resource.dopus.com/u/galaxyhub)\
**Post date:** [February 7, 2024, 6:28pm UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/1 "2024-02-07T18:28:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![errante](https://resource.dopus.com/user_avatar/resource.dopus.com/errante/32/61692_2.png) [@errante](https://resource.dopus.com/u/errante)\
**Post date:** [February 7, 2024, 6:34pm UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/2 "2024-02-07T18:34:12Z")

</div>

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

 ![image](https://resource.dopus.com/uploads/default/original/3X/6/6/660af4bc1b6ff535c1d194b403936d2101e0ed38.png)

Can you give a little example?

---

<div class="post-metadata">

**Author:** ![galaxyhub](https://resource.dopus.com/user_avatar/resource.dopus.com/galaxyhub/32/42793_2.png) [@galaxyhub](https://resource.dopus.com/u/galaxyhub)\
**Post date:** [February 7, 2024, 6:43pm UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/3 "2024-02-07T18:43:10Z")

</div>

nvm. found error. this works

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

```

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [February 7, 2024, 7:34pm UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/4 "2024-02-07T19:34:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)\
**Post date:** [February 7, 2024, 8:09pm UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/5 "2024-02-07T20:09:16Z")

</div>

> [@galaxyhub](#):
>
> Trying to measure time to enumerate a collection.

You could do it like this:

 ![image](https://resource.dopus.com/uploads/default/original/3X/8/1/819d7db7cc7f919c87d37357982164b18381ef2e.png)

---

<div class="post-metadata">

**Author:** ![galaxyhub](https://resource.dopus.com/user_avatar/resource.dopus.com/galaxyhub/32/42793_2.png) [@galaxyhub](https://resource.dopus.com/u/galaxyhub)\
**Post date:** [February 8, 2024, 1:48am UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/6 "2024-02-08T01:48:18Z")

</div>

many thanks all. Very useful.

---

<div class="post-metadata">

**Author:** ![galaxyhub](https://resource.dopus.com/user_avatar/resource.dopus.com/galaxyhub/32/42793_2.png) [@galaxyhub](https://resource.dopus.com/u/galaxyhub)\
**Post date:** [February 8, 2024, 3:12am UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/7 "2024-02-08T03:12:44Z")

</div>

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

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

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

DOpus.Output(diff);

```

---

<div class="post-metadata">

**Author:** ![errante](https://resource.dopus.com/user_avatar/resource.dopus.com/errante/32/61692_2.png) [@errante](https://resource.dopus.com/u/errante)\
**Post date:** [February 8, 2024, 3:37am UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/8 "2024-02-08T03:37:03Z")

</div>

Doing this doesn't work?

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

```

---

<div class="post-metadata">

**Author:** ![galaxyhub](https://resource.dopus.com/user_avatar/resource.dopus.com/galaxyhub/32/42793_2.png) [@galaxyhub](https://resource.dopus.com/u/galaxyhub)\
**Post date:** [February 8, 2024, 3:56am UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/9 "2024-02-08T03:56:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![galaxyhub](https://resource.dopus.com/user_avatar/resource.dopus.com/galaxyhub/32/42793_2.png) [@galaxyhub](https://resource.dopus.com/u/galaxyhub)\
**Post date:** [February 8, 2024, 4:10am UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/10 "2024-02-08T04:10:02Z")

</div>

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**.

---

<div class="post-metadata">

**Author:** ![errante](https://resource.dopus.com/user_avatar/resource.dopus.com/errante/32/61692_2.png) [@errante](https://resource.dopus.com/u/errante)\
**Post date:** [February 8, 2024, 4:31am UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/11 "2024-02-08T04:31:59Z")

</div>

Almost, and lxp already give you a hint before.

 ![image](https://resource.dopus.com/uploads/default/original/3X/e/e/eebad010ed2bb45dd72db0f2a0b5dabab83ebc31.png)

---

<div class="post-metadata">

**Author:** ![galaxyhub](https://resource.dopus.com/user_avatar/resource.dopus.com/galaxyhub/32/42793_2.png) [@galaxyhub](https://resource.dopus.com/u/galaxyhub)\
**Post date:** [February 8, 2024, 5:44am UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/12 "2024-02-08T05:44:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)\
**Post date:** [February 8, 2024, 5:45am UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/13 "2024-02-08T05:45:48Z")

</div>

> [@galaxyhub](#):
>
> Are they buggy ?

Both _modify_ objects, they don't _return_ anything.

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [February 8, 2024, 4:11pm UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/14 "2024-02-08T16:11:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![galaxyhub](https://resource.dopus.com/user_avatar/resource.dopus.com/galaxyhub/32/42793_2.png) [@galaxyhub](https://resource.dopus.com/u/galaxyhub)\
**Post date:** [February 9, 2024, 4:59pm UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/15 "2024-02-09T16:59:10Z")

</div>

![image](https://resource.dopus.com/uploads/default/original/3X/4/e/4e5cf1150d6aa39bf43f0fe7fa398b1445a71734.png)

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

```javascript
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

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [March 27, 2024, 9:56pm UTC](https://resource.dopus.com/t/how-to-convert-date-ms-to-integer/48743/16 "2024-03-27T21:56:31Z")

</div>

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