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 String
The day as a two digit string e.g. 01 for 1st of the month
dayOfWeek String
The day represented as a string e.g. Monday - Sunday
hours String
The hours as a two digit string in 24 hours e.g. 14 for 2pm
minutes String
The minutes as a two digit string e.g. 01
month String
The month as a two digit string e.g. 01 for January
seconds String
The seconds as a two digit string e.g. 01
time String
The time in H:i format e.g. 21:00 for 9pm
timestamp Number
The unix timestamp representing the date.
year String

The year in full i.e. 2015

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


Methods
daysSince(date) Number

Returns the number of days since a Date supplied. If the date supplied is in the future a negative number will be returned.

daysUntil(date) Number

Returns the number of days until a Date supplied. If the date supplied is in the past a negative number will be returned.

format([formatString]) 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.

isFuture() Boolean
Returns a boolean - true if the date is in the future (including time).
isPast() Boolean
Returns a boolean - true if the date is in the past (including time).
isToday() Boolean
Returns a boolean - true if the date is today’s date.
modify(modifyString) Date

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

<?ev
    date('yesterday').modify('+1 week');
?>
toString() String
The default representation of the Date as a String using format().


Date & time formats

The following formats are supported:

Year
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