# Class DateUtils

The `DateUtils` class exposes methods to convert strings, numbers and date objects to standard ISO 8601 Date objects, using the correct culture, language and format. It also offers methods to convert date objects to strings.

## Index

### Methods

- convertToStandardDate
- dateForQuery
- dateTimeForQuery
- dateTimeToString
- dateToString
- isValid
- keepOnlyDatePart
- monthToString
- offsetDateByDays
- timeBetween
- timeToString

## Methods

### Static convertToStandardDate

- convertToStandardDate(date: any): Date

- - Defined in utils/DateUtils.ts :199

  Tries to parse an argument of any type to a standard Date object.

  #### Parameters

  - ##### date: any

    The value to parse. Can be of any type (string, number, Date, etc.).

  #### Returns Date

  The parsed Date object, or `Invalid Date` if the `date` argument was not recognized as a valid date.

### Static dateForQuery

- dateForQuery(date: Date): string

- - Defined in utils/DateUtils.ts :232

  Creates a string from a Date object. The resulting string is in the date format required for queries.

  #### Parameters

  - ##### date: Date

    The Date object to create a string from.

  #### Returns string

  A string corresponding to the `date` argument value, in the `YYYY/MM/DD` format.

### Static dateTimeForQuery

- dateTimeForQuery(date: Date): string

- - Defined in utils/DateUtils.ts :243

  Creates a string from a Date object. The resulting string is in the datetime format required for queries.

  #### Parameters

  - ##### date: Date

    The Date object to create a string from.

  #### Returns string

  A string corresponding to the `date` argument value, in the `YYYY/MM/DD@HH:mm:ss` format.

### Static dateTimeToString

- dateTimeToString(date: Date, options?: IDateToStringOptions): string

- - Defined in utils/DateUtils.ts :394

  Creates a string from a Date object. The resulting string is formatted according to a set of options. This method calls `timeToString` to add time information to the date. If you need to create a date string without a timestamp, use the `dateToString` method instead.

  #### Parameters

  - ##### date: Date

    The date object to create a string from.

  - ##### Optional options: IDateToStringOptions

    The set of options to apply when formatting the resulting string. If you do not specify a value for this parameter, the method uses a default set of options.

  #### Returns string

  A date string corresponding to the `date` argument value, formatted according to the specified `options`.

### Static dateToString

- dateToString(date: Date, options?: IDateToStringOptions): string

- - Defined in utils/DateUtils.ts :316

  Creates a string from a Date object. The resulting string is formatted according to a set of options. This method calls `keepOnlyDatePart` to remove time information from the date. If you need to create a timestamp, use the `dateTimeToString` method instead.

  #### Parameters

  - ##### date: Date

    The Date object to create a string from.

  - ##### Optional options: IDateToStringOptions

    The set of options to apply when formatting the resulting string. If you do not specify a value for this parameter, the method uses a default set of options.

  #### Returns string

  A date string corresponding to the `date` argument value, formatted according to the specified `options`.

### Static isValid

- isValid(date: any): boolean

- - Defined in utils/DateUtils.ts :457

  Validates whether a value is an instance of Date.

  #### Parameters

  - ##### date: any

    The value to verify.

  #### Returns boolean

  `true` if the `date` argument is an instance of Date; `false` otherwise.

### Static keepOnlyDatePart

- keepOnlyDatePart(date: Date): Date

- - Defined in utils/DateUtils.ts :254

  Creates a cropped version of a Date object. The resulting object contains no time information.

  #### Parameters

  - ##### date: Date

    The original Date object to create a cropped Date object from.

  #### Returns Date

  A cropped Date object corresponding to the `date` argument value, excluding its time information.

### Static monthToString

- monthToString(month: number): string

- - Defined in utils/DateUtils.ts :446

  Creates a string from a number. The resulting string is the localized name of the month that corresponds to this number (e.g., `0` results in the localized version of `January`).

  #### Parameters

  - ##### month: number

    The number to create a string from. Minimum value is `0` (which corresponds to `January`). Maximum value is `11` (which corresponds to `December`).

  #### Returns string

  A string whose value is the localized name of the corresponding `month`.

### Static offsetDateByDays

- offsetDateByDays(date: Date, offset: number): Date

- - Defined in utils/DateUtils.ts :266

  Creates an offset version of a Date object. The offset is counted in days.

  #### Parameters

  - ##### date: Date

    The original Date object to create an offset Date object from.

  - ##### offset: number

    The number of days to add to (or subtract from) the `date` argument.

  #### Returns Date

  An offset Date object corresponding to the `date` argument value plus the `offset` value.

### Static timeBetween

- timeBetween(from: Date, to: Date): string

- - Defined in utils/DateUtils.ts :473

  Creates a string from two Date objects. The resulting string corresponds to the amount of time between those two dates.

  #### Parameters

  - ##### from: Date

    The Date object which contains the "oldest" value.

  - ##### to: Date

    The Date object which contains the "newest" value.

  #### Returns string

  A string whose value corresponds to the amount of time between `from` and `to`, or an empty string if either argument was undefined.

### Static timeToString

- timeToString(date: Date, options?: IDateToStringOptions): string

- - Defined in utils/DateUtils.ts :378

  Creates a string from a Date object. The string corresponds to the time information of the Date object.

  #### Parameters

  - ##### date: Date

    The Date object to create a string from.

  - ##### Optional options: IDateToStringOptions

    The set of options to apply when formatting the resulting string. If you do not specify a value for this parameter, the method uses a default set of options.

  #### Returns string

  A string containing the time information of the `date` argument, and formatted according to the specified `options`.

### Hierarchy

- DateUtils