Date

Extends Object. Representation of date and time.

Instantiation

You can create an instance of the Date object as below.

<?ev
    var today = date();
    
    // or
    
    var today = new Date();
?>


Construct parameters
dateString

String (optional)

If the dateString is not supplied the current date and time is assumed. The dateString may be any string that can be converted into a date and time Object. Here are some examples:

<?ev
    date('now');
    date('yesterday');
    date('tomorrow');
    date('+1 day');
    date('+1 week');
    date('last Sunday');
    date('next Monday');
?>

Note: Forward slash (/) signifies American M/D/Y formatting, a dash (-) signifies European D-M-Y and a period (.) signifies ISO Y.M.D. For example:

<?ev
    date("15.12.10"); // 10 Dec 2015

    date("11/12/15"); // 12 Nov 2015

    date("11-12-15"); // 11 Dec 2015
?>

Due to confusion over date formats we have adopted a default display format that's easier to read:

<?ev
    date("11 Aug 2015"); // 11 Aug 2015
?>
timezone

String (optional)

Dates and time are subject to timezones and are always stored and extracted from the database with the server's timezone, but are output to screen using the timezone for the current locale. When instantiating a Date object using EV Script the timezone of the current locale is assumed if this parameter is omitted. The timezone should be a valid identifier such as 'Europe/London'.



Properties
day

Type String

The day as a two digit string e.g. 01 for 1st of the month

dayOfWeek

Type String

The day represented as a string e.g. Monday - Sunday

hours

Type String

The hours as a two digit string in 24 hours e.g. 14 for 2pm

minutes

Type String

The minutes as a two digit string e.g. 01

month

Type String

The month as a two digit string e.g. 01 for January

seconds

Type String

The seconds as a two digit string e.g. 01

time

Type String

The time in H:i format e.g. 21:00 for 9pm

year

Type String

The year in full i.e. 2015

This year it is {{ date().year }}


Methods
format([String:format])

Returns String

A String representation of the Date object using the current locale's timezone. When the formatString is omitted the default format of d M Y is used e.g. 08 Aug 2015 (we rarely need to output time).

See supported formats below.

modify(String:modify)

Returns Date

Modifies the current Date object by a given amount and returns the original modified Date object.

<?ev
    date('yesterday').modify('+1 week');
?>
toString()

Returns String

The default representation of the Date as a String using format().



Date & time formats

The following formats are supported:

Year Example
Y Year as 4 digits 2015
y Year as 2 digits 15
Month
F A full textual representation of a month August
m Numeric representation of a month, with leading zeros 08
M A short textual representation of a month, three letters Aug
n Numeric representation of a month, without leading zeros 8
t Number of days in the given month 31
Day
d Day of the month, 2 digits with leading zeros 08
D A textual representation of a day, three letters Sat
j Day of the month without leading zeros 8
l A full textual representation of the day of the week (lowercase L) Saturday
S English ordinal suffix for the day of the month, 2 characters (works well with j) th
w Numeric representation of the day of the week (0 for Sunday - 6 for Saturday) 6
z Day of the year out of 365 0-365
Hours
g 12-hour format of an hour without leading zeros 1-12
G 24-hour format of an hour without leading zeros 0-23
h 12-hour format of an hour with leading zeros 01-12
H 24-hour format of an hour with leading zeros 01-23
Minutes
i Minutes with leading zeros 00-59
Seconds
s Seconds, with leading zeros 00-59
AM or PM
a Lowercase Ante meridiem and Post meridiem am / pm
A Uppercase Ante meridiem and Post meridiem AM / PM
Time (other)
O Difference to Greenwich time (GMT) in hours +0200
P Difference to Greenwich time (GMT) with colon between hours and minutes +02:00