0Pricing
Lua Academy · Lesson

Time Arithmetic

Add and compare times.

Time Is Just Numbers

Because os.time returns plain seconds, doing date math is mostly ordinary arithmetic. Add seconds to move forward, subtract to look back.

This lesson shows how to shift times, compare them, and find the gap between two moments.

Seconds in a Minute, Hour, Day

To work in larger units, remember the basic counts: 60 seconds in a minute, 3600 in an hour, and 86400 in a day.

Multiplying by these constants lets you express any duration in seconds.

print("Minute:", 60)
print("Hour:", 60 * 60)
print("Day:", 24 * 60 * 60)

All lessons in this course

  1. os.time and os.date
  2. Formatting Dates
  3. Time Arithmetic
  4. Measuring Durations
← Back to Lua Academy