#### Chris Wilfong

##### Member

What's the most efficient way to do this?

Thanks!

- Thread starter Chris Wilfong
- Start date

What's the most efficient way to do this?

Thanks!

One way is to use date_minute_span() and then using div and mod to convert the units.

Create:

Step:

Draw:

I decided not to use months as a unit as there are long months and short months in a year, and that would just cause confusion at a UX level. But if you want to use 30 days as a standardized month, then use mins div 43200 for months and (mins div 1440) mod 30 for days.

Create:

Code:

```
current_datetime = date_current_datetime();
target_datetime = date_create_datetime(2020, 2, 4, 18, 30, 0);
```

Code:

`current_datetime = date_current_datetime();`

Code:

```
var mins = date_minute_span(current_datetime, target_datetime);
draw_text(x, y, "You have " + string(mins div 1440) + " days, " + string((mins div 60) mod 24) + " hours, and " + string(round(mins mod 60)) + " minutes.");
```

Last edited:

Can you help me understand div and and mod? I get how days work but confused about hours and minutes.

div is integer division and mod is the remainder after integer division. The expressions should all be self-explanatory for anyone who remembers third grade math.

Can you help me understand div and and mod? I get how days work but confused about hours and minutes.

To add on to this, GMS2 added the modulo operator (%), so you don't have to use the mod keyword.div is integer division and mod is the remainder after integer division. The expressions should all be self-explanatory for anyone who remembers third grade math.

Code:

```
var foo = 5 mod 2;
//Functionally identical to
var foo = 5%2;
```

Yeahhh I don't know what elementary school you went to, but no third graders where I live would understand this. But I get it now.div is integer division and mod is the remainder after integer division. The expressions should all be self-explanatory for anyone who remembers third grade math.

Assuming they taught you to read in elementary school, you can also find the explanations in the manualYeahhh I don't know what elementary school you went to, but no third graders where I live would understand this. But I get it now.

div, mod (%)- Division and modulo, where div gives you the amount a value can be divided into producing only an integer quotient, while mod gives you only the remainder of a division.

Note that you can only div or mod usingintegervalues.