function datenum
datenum(
d: string | array<string | number>,
fmt?: string,
): number | array

Convert date and time to a serial date number (Unix).

Converts a given date and time to a Unix timestamp (serial date number). The function supports both date strings with a format and numeric arrays representing components of date and time.

Examples

Convert a date string to a Unix timestamp

import { assertEquals } from "jsr:@std/assert";

assertEquals(datenum('31-12-2014', 'DD-MM-YYYY'), 1419984000);

Convert an array of date strings to an array of Unix timestamps

import { assertEquals } from "jsr:@std/assert";

assertEquals(datenum(['31-12-2014', '31-01-2015'], 'DD-MM-YYYY'), [1419984000, 1422662400]);

Convert an array of date components to a Unix timestamp

import { assertEquals } from "jsr:@std/assert";

assertEquals(datenum([2015, 4, 5, 12, 20, 30, 0]), 1428236430);

Parameters

d: string | array<string | number>

The date input, which can be a single value or an array of date components.

optional
fmt: string

The format string to parse the date if the input is a date string.

Return Type

number | array

The Unix timestamp or an array of Unix timestamps.