GREL Date Functions

allen joslin edited this page Jan 26, 2016 · 13 revisions
Clone this wiki locally

Date functions supported by the OpenRefine Expression Language (GREL)

See also: All GREL functions.


Returns the current time.

toDate(o, boolean month_first / format1, format2, ... )

Returns o converted to a date object.

All other arguments are optional:

  • month_first: set false if the date is formatted with the day before the month.
  • formatN: attempt to parse the date using an ordered list of possible formats. See SimpleDateFormat for the syntax.

Examples: You can parse the cells "Nov-09" and "11/09" using


For a date of the form: "1/4/2012 13:30:00" use GREL function:

toDate(value,"dd/mm/YYYY H:m:s")

toString(o, optional string format)

When o is a date, format specifies how to format the date.

diff(date d1, date d2, optional string timeUnit)

For dates, returns the difference in given time units.

inc(date d, number value, string unit)

Returns a date changed by the given amount in the given unit of time. Unit defaults to 'hour'.

For example, if you want to decrement a date by 2 months:,'month')

datePart(date d, string unit)

Returns part of a date. Data type returned depends on the unit. Units supported are:

Unit Date part returned Returned data type Example using [date 2014-03-14T05:30:04Z] as value
years Year Number value.datePart("years") -> 2014
year Year Number value.datePart("year") -> 2014
months Month Number value.datePart("months") -> 2
month Month Number value.datePart("month") -> 2
weeks Week (of the year) Number value.datePart("weeks") -> 2
week Week (of the year) Number value.datePart("week") -> 3
w Week (of the year) Number value.datePart("w") -> 3
weekday Day of the week String value.datePart("weekday") -> Friday
hours Hour Number value.datePart("hours") -> 5
hour Hour Number value.datePart("hour") -> 5
h Hour Number value.datePart("h") -> 5
minutes Minute Number value.datePart("minutes") -> 30
minute Minute Number value.datePart("minute") -> 30
min Minute Number value.datePart("min") -> 30
seconds Seconds Number value.datePart("seconds") -> 04
sec Seconds Number value.datePart("sec") -> 04
s Seconds Number value.datePart("s") -> 04
milliseconds Millseconds Number value.datePart("milliseconds") -> 0
ms Millseconds Number value.datePart("ms") -> 0
S Millseconds Number value.datePart("S") -> 0
time Date expressed as milliseconds since the Unix Epoch Number value.datePart("time") -> 1394775004000