DateTime():startOf()
Sets the DateTime object to the start of a specified unit of time (e.g., start of the day, start of the month).
Signature
startOf(unit: string): DateTime
Parameters
Parameter | Type | Description |
---|---|---|
unit | string | The unit of time to set the start of. Supported units include:year , month , week , day , hour , minute , second |
Returns
- Type:
DateTime
- The current
DateTime
instance, allowing for method chaining.
Examples
local now = DateTime()
-- Set to the start of the current day
now:startOf("day")
toast("Start of day: " .. now:format("yyyy-MM-dd HH:mm:ss.SSS"))
-- Set to the start of the current month
now = DateTime() -- Reset
now:startOf("month")
toast("Start of month: " .. now:format("yyyy-MM-dd HH:mm:ss.SSS"))
-- Set to the start of the current year
now = DateTime() -- Reset
now:startOf("year")
toast("Start of year: " .. now:format("yyyy-MM-dd HH:mm:ss.SSS"))