In particular, we have .datePart("years")
If you have standardized ISO date formats already in your source data and don't need fancy parsing within the toDate() function, then you can try just this in GREL:
value.toDate().datePart("years")
if you already transformed your column and the values are already Date data type, then just do:
Sorry, I had assumed based on your original issue that you had a column that already had contained dates in a standard String format with yyyy-MM-dd. But now with your screenshot I see you actually have 4 digit Numbers (Integers)! Screenshots are so helpful!
To parse Strings into Dates, you can use the GREL .toDate() function as explained before at this link GREL functions | OpenRefine <-- What parts in it did not make sense to you? We can improve the docs with your feedback.
OpenRefine Date functions work on Dates or Strings. They do not work on Numbers.
That's probably something we should say directly in the first paragraph in our Docs. So I'll fix our Docs on that later.
So, in your case, you first need to undo the conversion of your String to Numbers and make them Strings again:
(you can use the Undo/Redo to select and click on an earlier step that converted them, or)
use the Cell Edit -> Common Transforms -> to Text
then use the Cell Edit -> Common Transforms -> to Date
@Gnoeee Click the docs link above that @tfmorris replied with. Reading our docs will show you lots of things you can learn. You can even Search our docs in the search bar in top-right corner of our website. Feel free to start a new thread if something isn't clear in our docs or you still have questions.
I understand that the ISO 8601-compliant extended format includes the month and day in addition to the year. Therefore, when converting strings to dates, it will automatically include these elements alongside the year.
For example:
The year alone is represented as: 1983
The full date in extended format is represented as: 1983-01-01T00:00:00Z
It would be helpful if the documentation page included an example that clearly distinguishes between representing just a year and a full date. This distinction can prevent confusion and ensure clarity for users working with date conversions.