Skip to content

DateTime and Date Functions

Nak edited this page Sep 18, 2022 · 4 revisions

Some simple date functions:

Returns Functions Description
Number NikNaks.DateTime.DaysInMonth( Number month, Number year ) Returns the days in the given month.
Bool NikNaks.DateTime.IsLeapYear( Number year ) Returns true if the given year is a leap-year.
Table NikNaks.DateTime.Calender( Number year ) Returns a table-structure with ["year"] and ["month"] as variables.

DateTime

DateTime is a simple object structure that allows you to manipulate date and time with a few simple functions.

Returns Functions Description
DateTime? NikNaks.DateTime.Get( Number? / String? / TimeDelta? / DateTime? var ) Returns a DateTime object matching the given Unix Time, matching the given String using the ISO-standard, TimeDelta from the current time or copy the DateTime given.

Examples on supported DataTime String-Formats:

"Sun, 01 Sep 2022 00:12:00"
"September 01, 2022 12:12 AM"
"2022-09-01T00:12:00+02:00"
"2022/09/1"
"2022-09-01T07:12:00-5:00"
"2022-09-01 02:12:00Z"
"Thu, 01 Sep 2022 00:12:00"

DateTime Functions

Returns Functions Description
TimeDelta DateTime:TimeUntil( Number?/String?/DateTime? var ) Returns the TimeDelta object until the given date. If no variable is given, it will use the current time.
String/Table DateTime:ToDate( String format ) Returns the date/time as a formatted string or in a table.
See: https://wiki.facepunch.com/gmod/os.date
Number DateTime:GetUnix() Returns Unix Time as a Number.

DateTime objects can also be added or subtracted with unix-numbers or another DateTime.

[DateTime] = [DateTime] - 86400 // Returns a new DateTime object that are 24 hours behind.
[DateTime] = [DateTime] + NikNaks.TimeDelta.Hour // Returns a new DateTime object that is 1hour ahead.
[TimeDelta] = [DateTime] - [DateTime] // Returns a [TimeDelta] object between the two DateTimes.

DateTime objects can also be compared with each other.

if( [DateTime] > [DateTime] ) then print("The first DateTime is newer") end
if( [DateTime] == [DateTime] ) then print("The two DateTime is the same") end
if( [DateTime] < [DateTime] ) then print("The first DateTime is older") end

DateTime Variables

Variable Names

  • NikNaks.DateTime.day A variable with the current day.
  • NikNaks.DateTime.month A variable with the current month.
  • NikNaks.DateTime.year A variable with the current year.
  • NikNaks.DateTime.yesterday A variable returning the DateTime 24hours behind.
  • NikNaks.DateTime.now / NikNaks.DateTime.today A variable returning the current DateTime.
  • NikNaks.DateTime.tomorrow A variable returning the DateTime 24 hours ahead.

Nik Naks Wiki


Features:

Clone this wiki locally