DateUtils

DateUtils

DateUtils manipulates local (without timezones) dates stored a number in the YYYYMMDD form. Function names are meant to tell what the input and output date types they work on. In terms of understanding the data types used to represent dates: int YYYYMMDD e.g., 20180322 str "3/22/[20]18" (or similar international format) str2 "3/22/18" (or similar international format) str4 "3/22/2018" (or similar international format) SQL "2018-03-22" Date JavaScript Date object

Constructor

new DateUtils()

Source:

Methods

(static) calendar(d) → {number}

Source:
Convert a julian date into an integer date.
Parameters:
Name Type Description
d number d the julian date
Returns:
the integer date formatted as YYYYMMDD
Type
number

(static) dateAddDays(dt, days) → {Date}

Source:
Add days to a Date object
Parameters:
Name Type Description
dt Date
days number number of days to add or subtract
Returns:
Type
Date

(static) dateToInt(dt) → {number}

Source:
Deprecated:
  • Use DateUtils.toInt() Convert a Date object to YYYYMMDD int
See:
  • DateUtils.toInt()
Parameters:
Name Type Description
dt Date
Returns:
Type
number

(static) day(dt) → {number}

Source:
Return the day portion of a date.
Parameters:
Name Type Description
dt number | Date integer date formatted as YYYYMMDD or a Date object
Returns:
Type
number

(static) dayOfWeek(dt) → {number}

Source:
Takes an integer date formatted as YYYYMMDD and returns an integer indicating the day of the week. 0 Sunday 1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday
Parameters:
Name Type Description
dt number integer date formatted as YYYYMMDD
Returns:
an integer indicating the day of the week
Type
number

(static) dayOfWeekName(dt) → {string}

Source:
Takes an integer date formatted as YYYYMMDD and returns the name of the day of the week as a string such as "Sunday", "Monday", etc.
Parameters:
Name Type Description
dt number integer date formatted as YYYYMMDD
Returns:
the name of the day of the week
Type
string

(static) daysDifference(dt1, dt2) → {number}

Source:
Return the number of days between two dates.
Parameters:
Name Type Description
dt1 number date formatted as YYYYMMDD
dt2 number date formatted as YYYYMMDD
Returns:
returns the number of days dt1 - dt2
Type
number

(static) detectDateFormat(localeopt) → {string}

Source:
Detects the date format based on the given locale.
Parameters:
Name Type Attributes Default Description
locale string <optional>
navigator.language optional locale used to determine the date format.
Returns:
The detected date format. Possible values are 'MM/DD/YYYY', 'DD/MM/YYYY', or 'Unknown Format'.
Type
string

(static) intAddDays(dt, days) → {int}

Source:
Add days to an int date
Parameters:
Name Type Description
dt number int date YYYYMMDD
days number number of days to add or subtract
Returns:
Type
int

(static) intToDate(dt) → {Date}

Source:
Convert an int date YYYYMMDD to a JavaScrip Date object
Parameters:
Name Type Description
dt number
Returns:
Type
Date

(static) intToSQL(dt) → {string}

Source:
Convert a date to string yyyy-mm-dd
Parameters:
Name Type Description
dt YYYYMMDD, YYYYMMDDHHMM, Date, milliseconds, or string
Returns:
Type
string

(static) intToStr2(dt, tzopt) → {string}

Source:
Convert a date to a locale-appropriate string using 2-digit year: "mm/dd/yy", "dd/mm/yy", etc.
Parameters:
Name Type Attributes Description
dt number | string | Date – YYYYMMDD, Date, millis, or numeric string
tz string <optional>
– IANA zone (e.g. "America/New_York"); omit/falsy ⇒ use the host’s zone
Returns:
Type
string

(static) intToStr4(dt, tzopt) → {string}

Source:
Convert a numeric date to a locale-appropriate string (e.g. "05/07/2025" or "07/05/2025" depending on the user’s locale).
Parameters:
Name Type Attributes Description
dt number | string | Date – value in YYYYMMDD form *or* milliseconds
tz string <optional>
– IANA zone name; omit/falsy ⇒ host’s zone
Returns:
Type
string

(static) isSQLDate(val) → {boolean}

Source:
Verify SQL date formatted like YYYY-MM-DD
Parameters:
Name Type Description
val string
Returns:
Type
boolean

(static) isValid(dt) → {boolean}

Source:
Is dt a valid date?
Parameters:
Name Type Description
dt number, string, or date
Returns:
true if valid date
Type
boolean

(static) julian(dt) → {number}

Source:
Convert an integer date into a julian date.
Parameters:
Name Type Description
dt number integer date formatted as YYYYMMDD
Returns:
the julian date
Type
number

(static) longFormat(dt) → {string}

Source:
Formats a date into a string format as in: Mon January 12, 2021
Parameters:
Name Type Description
dt number integer date formatted as YYYYMMDD
Returns:
Type
string

(static) millsToInt(m) → {number}

Source:
Deprecated:
  • Use DateUtils.toInt() Convert a number of milliseconds since 1970 UTC to an integer date YYYYMMDD. This takes into account the local timezone.
See:
  • DateUtils.toInt()
  • DateTimeUtils.toMilliseconds()
Parameters:
Name Type Description
m number number of milliseconds since 1970 UTC
Returns:
YYYYMMDD
Type
number

(static) month(dt) → {number}

Source:
Return the month portion of a date.
Parameters:
Name Type Description
dt number | Date integer date formatted as YYYYMMDD or a Date object
Returns:
Type
number

(static) monthName(dt) → {string}

Source:
Takes an integer date formatted as YYYYMMDD and returns the name of the month as a string such as "January", "February", etc.
Parameters:
Name Type Description
dt number integer date formatted as YYYYMMDD
Returns:
the name of the day of the week
Type
string

(static) monthsDifference(idt1, idt2) → {number}

Source:
Return the number of months between two dates.
Parameters:
Name Type Description
idt1 number Date or integer date YYYYMMDD
idt2 number Date or integer date YYYYMMDD
Returns:
number of months between the two dates
Type
number

(static) SQLtoInt(dateString) → {number}

Source:
Converts a string date ("YYYY-MM-DD") to an integer of the form YYYYMMDD. Bad dates return 0
Parameters:
Name Type Description
dateString string
Returns:
Type
number

(static) strToInt(dateString) → {number}

Source:
Converts a string in any of the following formats to an int YYYYMMDD: "mM/dD/yyYY" or "dD/mM/yyYY" (depending on locale) "mmddyyyy" or "ddmmyyyy" (depending on locale) "yyyymmdd" "YYYY-MM-DD" or "YYYY/MM/DD" Bad dates return 0 Takes into account local standard formats.
Parameters:
Name Type Description
dateString string
Returns:
Type
number

(static) today() → {number}

Source:
Returns the current date as an int formatted as YYYYMMDD
Returns:
Type
number

(static) toInt(dt) → {number}

Source:
Convert a JavaScript Date, a string, an integer date in the form of YYYYMMDD, YYYYMMDDHHMM, or the number of milliseconds since the epoch and returns a date formated as an integer in YYYYMMDD format.
Parameters:
Name Type Description
dt number, string, or date
Returns:
YYYYMMDD or zero
Type
number

(static) year(dt) → {number}

Source:
Return the year portion of a date.
Parameters:
Name Type Description
dt number | Date integer date formatted as YYYYMMDD or a Date object
Returns:
Type
number