@Date (JavaScript)

Creates a date and time.

Defined in

@Functions (JavaScript)

Syntax

@Date(time:Date) : Date

@Date(years:int, months:int, days:int) : Date

@Date(years:int, months:int, days:int, hours:int, minutes:int, seconds:int) : Date

Parameter Description
time A date and time.
seconds Second of the date and time.
minutes Minute of the date and time.
hours Hour of the date and time.
days Day of the date and time.
months Month of the date and time.
years Year of the date and time.
Return value Description
Date The new date and time.

Usage

This function provides the date and time as follows:
  • If the parameter list specifies a Date object, this function uses only the date portion and sets the time to 0 hours.
  • If the parameter list specifies years, months, and days, this function sets the date as specified and sets the time to 0 hours.
  • If the parameter list specifies years, months, days, hours, minutes, and seconds, this function sets the date and time as specified.

Examples

This example constructs a date and time from a Date object.
function p(stuff) {
	print("<<<" + stuff + ">>>");
}

var now = @Now();
var date1 = @Date(now);
p("Now = " + now); // <<<Now = 4/7/06 4:49 PM>>>
p("Date = " + date1); // <<<Date = 4/7/06 12:00 AM>>>

This example constructs a date and time by using the date from @Today and specifying the time literally.

function p(stuff) {
	print("<<<" + stuff + ">>>");
}

var date1 = @Today();
var year = @Year(date1);
var month = @Month(date1);
var day = @Day(date1);
var today = @Date(year, month, day, 13, 30, 0);
p("Today at 1:30PM = " + today.toLocaleString());

This example constructs a date and time 24 hours before the current time by using the date from @Yesterday and the time from @Now.

function p(stuff) {
	print("<<<" + stuff + ">>>");
}

var date1 = @Yesterday();
var year = @Year(date1);
var month = @Month(date1);
var day = @Day(date1);
var date2 = @Now();
var hour = @Hour(date2);
var minute = @Minute(date2);
var second = @Second(date2);
var yesterday = @Date(year, month, day, hour, minute, second);
p("24 hours ago = " + yesterday.toLocaleString());