Working with a CSV file that has a column of dates expressed in Epoch time, I've added a column based on this column, where I would like to convert these Epoch Time values to 'regular' dates (dd-MM-yyyy HH:MM:SS UTC +2:00, to be precise).
The OpenRefine User manual helpfully tells me there's a GREL function for this:
timeSinceUnixEpochToDate(duration, scale)
Converts a time as measured by the duration since the Unix Epoch (1970-01-01) to a date object. The second parameter indicates the unit of the duration, and can be "second"
, "millisecond"
or "microsecond"
. If the unit is not provided, it is assumed to be "second"
.
This function is available since OpenRefine 3.6.
This documentation tells me what to fill in for the second parameter, but not what I should put in the first. Same goes for the Help function built into the 'Add column based on column' dialog:
(number n, string unit (optional, defaults to 'seconds'))
returns: date(OffsetDateTime)
What should I give this Function as a parameter to return the value in a Date format?
| |
The OpenRefine User manual helpfully tells me there's a GREL function for this:
timeSinceUnixEpochToDate(duration, scale)
Converts a time as measured by the duration since the Unix Epoch (1970-01-01) to a date object. The second parameter indicates the unit of the duration, and can be "second"
, "millisecond"
or "microsecond"
. If the unit is not provided, it is assumed to be "second"
.
This function is available since OpenRefine 3.6.
This documentation tells me what to fill in for the second parameter, but not what I should put in the first. Same goes for the Help function built into the 'Add column based on column' dialog:
(number n, string unit (optional, defaults to 'seconds'))
returns: date(OffsetDateTime)
What should I give this Function as a parameter to return the value in a Date format?
The first parameter is a number, as mentioned in the help. You can put that first parameter either before the function using the dot notation or inside the parentheses, but not both. value.function(value, "seconds") is equivalent to function(value, value, "seconds"), which is obviously not what you want.
Tom
Thanks, Tom, I much appreciate your responding. And I understand your point. Yet I still don't know what to put in as a parameter, as it will nog give me a value for 'value'
Could you kindly tell me how I can format this function call to make it return the date for the values it's based upon?
Are you perhaps passing it a string that looks like a number, rather than an actual number? Try replacing "value" with "toNumber(value)" or use the Edit cells -> Common transforms -> To number menu item to convert the entire column to numbers.
Also, the trailing 000 makes me think that your values aren't seconds, but milliseconds.
timeSinceUnixEpochToDate(1593417769000,"millisecond") evaluates to [date 2020-06-29T08:02:49Z]
Tom
All the above seem to do the trick. Much, much thanks, Tom!