Skip to main content

DateTime Library Reference

The datetime library provides functions for working with dates and times in EasyBite. All date values are represented as strings in "YYYY-MM-DD" format and time values in "HH:MM:SS" format. You can import the entire module with import datetime and call functions as datetime.today(), or import specific functions with from datetime import today, datediff, timeadd, etc.


Available Functions

FunctionParametersDescription
today()Returns the current date as a string "YYYY-MM-DD".
timenow()Returns the current local time as a string "HH:MM:SS".
datediff(date1, date2)date1, date2 (strings "YYYY-MM-DD")Returns the number of days from date1 to date2.
dateadd(date, days)date (string), days (number)Adds days days to date, returns new date string.
dateformat(date, format)date (string), format (format string)Formats date according to format (e.g. "%b %d, %Y"), returns the formatted string.
dateparse(dateString, format)dateString, format (strings)Parses dateString using format, returns date in "YYYY-MM-DD".
timediff(time1, time2)time1, time2 (strings "HH:MM:SS")Returns the difference in seconds from time1 to time2.
timeadd(time, unit, interval)time (string), unit (string), interval (number)Adds interval of unit ("seconds", "minutes", "hours") to time, returns new "HH:MM:SS".
timeformat(time, format)time (string), format (format string)Formats time according to format (e.g. "%I:%M %p"), returns the formatted string.
timeparse(timeString, format)timeString, format (strings)Parses timeString using format, returns time in "HH:MM:SS".

Examples

1. today()

import datetime
set currentDate to datetime.today()
show(currentDate)
// Output (example):
// 2025-04-20

from datetime import today
set todayDate to today()
show(todayDate)
// Output (example):
// 2025-04-20

2. timenow()

import datetime
set now to datetime.timenow()
show(now)
// Output (example):
// 14:35:07

from datetime import timenow
set currentTime to timenow()
show(currentTime)
// Output (example):
// 14:35:07

3. datediff(date1, date2)

import datetime
set diff to datetime.datediff("2025-04-10", "2025-04-15")
show(diff)
// Output:
// 5

from datetime import datediff
set daysBetween to datediff("2025-01-01", "2025-04-20")
show(daysBetween)
// Output:
// 109

4. dateadd(date, days)

import datetime
set newDate to datetime.dateadd("2025-04-20", 10)
show(newDate)
// Output:
// 2025-04-30

from datetime import dateadd
set future to dateadd("2025-04-20", -5)
show(future)
// Output:
// 2025-04-15

5. dateformat(date, format)

import datetime
set formatted to datetime.dateformat("2025-04-20", "%B %d, %Y")
show(formatted)
// Output:
// April 20, 2025

from datetime import dateformat
set f2 to dateformat("2025-04-20", "%m/%d/%Y")
show(f2)
// Output:
// 04/20/2025

6. dateparse(dateString, format)

import datetime
set parsed to datetime.dateparse("20-04-2025", "%d-%m-%Y")
show(parsed)
// Output:
// 2025-04-20

from datetime import dateparse
set p2 to dateparse("April 20, 2025", "%B %d, %Y")
show(p2)
// Output:
// 2025-04-20

7. timediff(time1, time2)

import datetime
set secondsDiff to datetime.timediff("12:00:00", "14:30:00")
show(secondsDiff)
// Output:
// 9000

from datetime import timediff
set sd to timediff("23:59:00", "00:01:00")
show(sd)
// Output:
// -1438

8. timeadd(time, unit, interval)

import datetime
set t1 to datetime.timeadd("12:00:00", "hours", 3)
show(t1)
// Output:
// 15:00:00

from datetime import timeadd
set t2 to timeadd("23:50:00", "minutes", 15)
show(t2)
// Output:
// 00:05:00

9. timeformat(time, format)

import datetime
set tf to datetime.timeformat("14:35:07", "%I:%M %p")
show(tf)
// Output:
// 02:35 PM

from datetime import timeformat
set tf2 to timeformat("07:05:00", "%H:%M")
show(tf2)
// Output:
// 07:05

10. timeparse(timeString, format)

import datetime
set tp to datetime.timeparse("2:35 PM", "%I:%M %p")
show(tp)
// Output:
// 14:35:00

from datetime import timeparse
set tp2 to timeparse("07-05-00", "%H-%M-%S")
show(tp2)
// Output:
// 07:05:00

Conclusion

The datetime library in EasyBite gives you all the tools to obtain, manipulate, compare, format, and parse dates and times:

  • Import the whole module: import datetimedatetime.function(...)
  • Import specific functions: from datetime import today, datediff, timeaddtoday(), datediff(...), timeadd(...)

Choose the import style that makes your code most readable and concise.