Intro to the date methods
Note
In the function editor, you can perform any JS method, using any value from cookies, variables, parameters, request responses, inputs or forms. Be sure to use the parameters correctly.
Date.now()
Description Returns the current timestamp in milliseconds (since January 1, 1970). Used for timing operations or unique IDs.
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
return (timestamp = Date.now()); // Result: 1718035200000 (example value)
getFullYear()
Description Extracts the year (4 digits) from a Date object. Ideal for age calculations or date displays.
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
const today = new Date();
return today.getFullYear(); // Result: 2025 (current year)
getMonth()
Description Returns the month of a Date object (0 = January, 11 = December). Combine with +1
for human-readable formats.
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
const date = new Date('2025-02-25');
return date.getMonth() + 1; // Result: 2 (Feb)
getDate()
Description Gets the day of the month (1-31) from a Date object. Useful for deadlines or calendar features.
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
const eventDate = new Date('2025-02-25');
return eventDate.getDate(); // Result: 25
getHours() & getMinutes()
Description - getHours()
: Returns the hour (0-23) of a Date object. - getMinutes()
: Returns the minutes (0-59).
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
const now = new Date();
return now.getHours(); // 14 (2 PM) const minutes = now.getMinutes(); // 30
toISOString()
Description Converts a Date object to an ISO 8601 string (e.g., "2024-07-20T12:00:00.000Z"
). Standard format for APIs and databases.
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
const date = new Date();
return date.toISOString(); // Result: "2024-07-20T12:00:00.000Z"
toLocaleDateString()
Description Converts a Date object to a locale-specific date string. Customizable for regional formats (e.g., "07/20/2024"
vs "20/07/2024"
).
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
const date = new Date();
return date.toLocaleDateString('en-US'); // Result: "7/20/2024"