Table of Contents

Products, services and company names referenced in this document may be either trademarks or registered trademarks of their respective owners.

Copyright © 2017–2020 EVL Tool, s.r.o.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts.

Date and Timestamp

Format string

Default formatting string:

timestamp: "%Y-%m-%d %H:%M:%S"  = "%F %T"  
date     : "%Y-%m-%d"           = "%F"

All possible format strings:


a literal ‘%


locale’s abbreviated weekday name (e.g. ‘Sun’)


locale’s full weekday name (e.g. ‘Sunday’)


locale’s abbreviated month name (e.g. ‘Jan’)


locale’s full month name (e.g. ‘January’)


locale’s date and time (e.g. ‘Thu Mar 3 23:05:25 2005’)


century; like ‘%Y’, except omit last two digits (e.g. ‘20’)


day of month (e.g. ‘01’)


date; same as ‘%m/%d/%y


day of month, space padded; same as ‘%_d


full date; same as ‘%Y-%m-%d


last two digits of year of ISO week number (see ‘%G’)


year of ISO week number (see ‘%V’); normally useful only with ‘%V


same as ‘%b


hour (‘00’..‘23’)


hour (‘01’..‘12’)


day of year (‘001’..‘366’)


hour, space padded (‘ 0’..‘23’); same as ‘%_H


hour, space padded (‘ 1’..‘12’); same as ‘%_I


month (‘01’..‘12’)


minute (‘00’..‘59’)


a newline


locale’s equivalent of either ‘AM’ or ‘PM’; blank if not known


like ‘%p’, but lower case


locale’s 12-hour clock time (e.g. ‘11:11:04 PM’)


24-hour hour and minute; same as ‘%H:%M


seconds since ‘1970-01-01 00:00:00 UTC


second (‘00’..‘60’)


a tab


time; same as ‘%H:%M:%S


day of week (‘1’..‘7’); ‘1’ is Monday


week number of year, with Sunday as first day of week (‘00’..‘53’)


ISO week number, with Monday as first day of week (‘01’..‘53’)


day of week (‘0’..‘6’); ‘0’ is Sunday


week number of year, with Monday as first day of week (‘00’..‘53’)


locale’s date representation (e.g. ‘12/31/99’)


locale’s time representation (e.g. ‘23:13:48’)


last two digits of year (‘00’..‘99’)



By default, date pads numeric fields with zeroes. The following optional flags may follow ‘%’.


(hyphen) do not pad the field


(underscore) pad with spaces


(zero) pad with zeros


use upper case if possible


use opposite case if possible

EVD definition

Example of definition date and timestamp in evd file. The following dates data types definition are equivalent.

valid_from  date
valid_from  date("%F")
valid_from  date("%Y-%m-%d")

Following timestamps are all the same.

request_dt  timestamp
request_dt  timestamp("%F %T")
request_dt  timestamp("%Y-%m-%d %H:%M:%S")

Declaration in mapping

The following declarations are equivalent.

static timestamp min_date(1970,1,1,0,0,0);
static timestamp min_date("1970-01-01 00:00:00");
static timestamp min_date("1970-01-01 00:00:00", "%Y-%m-%d %H:%M:%S");
static timestamp min_date = timestamp::from_epoch_time(0);
static date min_date(1970,1,1);
static date min_date("1970-01-01");
static date min_date("1970-01-01", "%Y-%m-%d");

Manipulation, comparison

Lets have ‘timestamp ts(2017,5,31,19,37,0)’ and ‘date dt(2018,1,14)’ in the following examples.

Methods switching date and timestamp data type:


returns ‘2017-05-31’, i.e. cut off time and return date data type


returns ‘2018-01-14 00:00:00’, i.e. add ‘00:00:00’ and return timestamp data type

Following methods return appropriate values as ‘int’.

ts.year()       -- 2017
dt.year()       -- 2018
ts.month()      -- 5
dt.month()      -- 1
ts.day()        -- 31
dt.day()        -- 14
ts.hour()       -- 19
ts.minute()     -- 37
ts.second()     -- 0
ts.epoch_time() -- 1496169420
ts.yearday()    -- 151
dt.yearday()    -- 14
ts.weekday()    -- 3 (Wednesday)
dt.weekday()    -- 0 (Sunday)

In the context of string, method ‘weekday()’ returns ‘sunday’, ...

weekday()’ returns ‘0’ for Sunday, ‘1’ for Monday, …, ‘6’ for Saturday.

These methods convert date and timestamp to string:

string str1 = ts.to_string();    // 2017-05-31 19:37:00,
                                 // i.e. uses default format string
string str2 = ts.to_string("%Y%m%d%H");     // 2017053119
string str3 = min_date.to_string("%Y%m%d"); // 19700101

Comparison:==’, ‘!=’, ‘<’, ‘>’, ‘<=’, ‘>=’.

if (ts >= timestamp(1990,1,1) { ... }

Addition, subtraction:

ts += 65;          // add 65 seconds, i.e. 2017-05-31 19:38:05
ts--;              // 2017-05-31 19:38:04
date d(2017,5,31);
d -= 35;           // subtract 35 days, i.e. 2017-04-26

ts.add_year(1);    // 2018-05-31 19:38:04
d.add_month(-1);   // 2017-03-26
ts.add_day(6);     // 2018-06-06 19:38:04
ts.add_hour(-2);   // 2018-05-31 17:38:04
ts.add_minute(3);  // 2018-05-31 19:41:04
ts.add_second(-6); // 2018-05-31 19:37:58

The difference between ‘ts.add_second(10)’ and ‘ts+10’ is that in the first case we modify the object itself, but in the second case new value is returned. One can use then for example ‘ts.add_hour(2).add_minute(3)’.


auto diff = ts - timestamp(2018,5,31,19,36,57); // 61 (seconds)
auto diff = d - date("2017-04-02");             // -6 (days)

Let’s summarize the logic:

date - int  => date          timestamp - int       => timestamp
date - date => int           timestamp - timestamp => int