date_add
pub fun date_add(date: Int, amount: Int, unit: Text): Int?
Adds a value to a date passed in the unix epoch format in milliseconds.
Example : date_add(date, 3, "days")
Available units:
- years
- months
- days
- hours
- minutes
- seconds
Usage
import { date_add } from "std/date"
let date = date_now() // Example value: 1678887000
let new_date = date_add(date, 5, "hours") // Example value: 1678890600
date_format_posix
pub fun date_format_posix(date: Int, format: Text = "%F %T", utc: Bool = false): Text?
Transform date from unix epoch to a human-readable format described by a posix format string.
If no format is specified, "%F %T" is used.
For more info about format type "man date" in your shell or see https://www.gnu.org/software/coreutils/date.
Format includes the following patterns:
%%- a literal %%a- locale's abbreviated weekday name (e.g., Sun)%A- locale's full weekday name (e.g., Sunday)%b- locale's abbreviated month name (e.g., Jan)%B- locale's full month name (e.g., January)%d- day of month (e.g., 01)%D- date; same as %m/%d/%y%F- full date; like %+4Y-%m-%d%H- hour (00..23)%I- hour (01..12)%m- month (01..12)%M- minute (00..59)%N- nanoseconds (000000000..999999999)%p- locale's equivalent of either AM or PM; blank if unknown%T- time; same as %H:%M:%S%Y- year
Usage
import { date_format_posix } from "std/date"
let date = date_now() // Example value: 1678887000
echo date_format_posix(date) // Outputs: 2023-03-15 14:30:00
date_from_posix
pub fun date_from_posix(date: Text, format: Text = "%F %T", utc: Bool = false): Int?
Transforms date from a format described by a posix format string to a unix epoch format (seconds since the Epoch (1970-01-01 00:00 UTC)).
If no format is specified, "%F %T" format is used.
For more info about format type "man date" on your shell or go to https://www.gnu.org/software/coreutils/date.
Usage
import { date_from_posix } from "std/date"
let date = "2023-03-15 14:30:00"
echo date_from_posix(date) // Output: 1678887000
date_now
pub fun date_now(): Int
Returns the current timestamp (seconds since the Epoch (1970-01-01 00:00 UTC)).
Usage
import { date_now } from "std/date"
let date = date_now() // Example value: 1678887000
date_sub
pub fun date_sub(date: Int, amount: Int, unit: Text): Int?
Subtracts a value from a date passed in the unix epoch format in milliseconds.
Example : date_sub(date, 5, "hours")
Available units:
- years
- months
- days
- hours
- minutes
- seconds
Usage
import { date_sub } from "std/date"
let date = date_now() // Example value: 1678887000
let new_date = date_sub(date, 5, "hours") // Example value: 1678882200