# Only Year Please

**URL:** <https://forum.openrefine.org/t/only-year-please/1453>\
**Category:** Data cleaning and transformations\
**Tags:** wikidata\
**Created:** [April 13, 2024, 6:48pm UTC](https://forum.openrefine.org/t/only-year-please/1453 "2024-04-13T18:48:31Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaankale](https://avatars.discourse-cdn.com/v4/letter/k/b9e5f3/32.png) [@Kaankale](https://forum.openrefine.org/u/Kaankale)\
**Post date:** [April 13, 2024, 6:48pm UTC](https://forum.openrefine.org/t/only-year-please/1453/1 "2024-04-13T18:48:31Z")

</div>

Hi,

Kindly requesting how to convert numerical value (Example: '1850') into Date value with only a four digit Year? No months or days required.

Everytime I convert to date, OpenRefine automatically adds '1850-01-01', but I only require year for Wikidata.

---

<div class="post-metadata">

**Author:** ![thadguidry](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/thadguidry/32/653_2.png) [@thadguidry](https://forum.openrefine.org/u/thadguidry)\
**Post date:** [April 13, 2024, 11:34pm UTC](https://forum.openrefine.org/t/only-year-please/1453/2 "2024-04-13T23:34:20Z")

</div>

We have some great documentation on this starting here, take a look! :  
[Exploring data - Dates | OpenRefine](https://openrefine.org/docs/manual/exploring#dates)  
and  
[GREL functions - Dates | OpenRefine](https://openrefine.org/docs/manual/grelfunctions#date-functions)

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:

`value.datePart("years")`

---

<div class="post-metadata">

**Author:** ![Kaankale](https://avatars.discourse-cdn.com/v4/letter/k/b9e5f3/32.png) [@Kaankale](https://forum.openrefine.org/u/Kaankale)\
**Post date:** [April 14, 2024, 6:45am UTC](https://forum.openrefine.org/t/only-year-please/1453/3 "2024-04-14T06:45:27Z")

</div>

Thank you for the swift reply and the resources provided.

value.datePart("years") is working perfectly for already changed date values.

Is there a way to convert a column with numerical values (Example: '1850') to Date Value?

None of the options in the resources or your examples seem to work? Would I need to manually convert each cell?

---

<div class="post-metadata">

**Author:** ![thadguidry](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/thadguidry/32/653_2.png) [@thadguidry](https://forum.openrefine.org/u/thadguidry)\
**Post date:** [April 14, 2024, 8:25am UTC](https://forum.openrefine.org/t/only-year-please/1453/4 "2024-04-14T08:25:24Z")

</div>

Did you have problems if you tried the GREL function:  
`value.toDate()`

or generally using the Column menu dropdown to try the Common transform to change the data type to Date? [Cell editing | OpenRefine](https://openrefine.org/docs/manual/cellediting#data-type-transforms)

---

<div class="post-metadata">

**Author:** ![Kaankale](https://avatars.discourse-cdn.com/v4/letter/k/b9e5f3/32.png) [@Kaankale](https://forum.openrefine.org/u/Kaankale)\
**Post date:** [April 14, 2024, 10:57am UTC](https://forum.openrefine.org/t/only-year-please/1453/5 "2024-04-14T10:57:49Z")

</div>

> [@thadguidry](#):
>
> value.toDate()

Hi,

It only seems to do this for the first value and not the rest. Do I need to select the others in some way?

---

<div class="post-metadata">

**Author:** ![thadguidry](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/thadguidry/32/653_2.png) [@thadguidry](https://forum.openrefine.org/u/thadguidry)\
**Post date:** [April 14, 2024, 12:42pm UTC](https://forum.openrefine.org/t/only-year-please/1453/6 "2024-04-14T12:42:17Z")

</div>

1. Did you use the Column menu operation? Edit Cells -\> Common Transform -\> to Date on your column?

2. Or did you instead use the Edit button on a Cell?

(see my issue with some screenshots which is not for your case, but can be used as a guide to understand what I am talking about  
[Using Cell Edit button to change String to Date data type gives Uncaught RangeError · Issue #6534 · OpenRefine/OpenRefine (github.com)](https://github.com/OpenRefine/OpenRefine/issues/6534)  
)

A screenshot from you would certainly help us to understand better.  
You can copy/paste an image in your reply, or use the Upload button.

---

<div class="post-metadata">

**Author:** ![Kaankale](https://avatars.discourse-cdn.com/v4/letter/k/b9e5f3/32.png) [@Kaankale](https://forum.openrefine.org/u/Kaankale)\
**Post date:** [April 14, 2024, 1:46pm UTC](https://forum.openrefine.org/t/only-year-please/1453/7 "2024-04-14T13:46:25Z")

</div>

I used Edit Cells -\> Common Transform -\> to Date on your column, but only the first cell is changing?

Only changed the first cell;

![image](https://europe1.discourse-cdn.com/flex017/uploads/openrefine/original/1X/0f0f65b0d41e5fef05f8876755da9ee4e9726e70.png)

I have tried refreshing, closing and opening again. Any advise?

---

<div class="post-metadata">

**Author:** ![Kaankale](https://avatars.discourse-cdn.com/v4/letter/k/b9e5f3/32.png) [@Kaankale](https://forum.openrefine.org/u/Kaankale)\
**Post date:** [April 14, 2024, 1:47pm UTC](https://forum.openrefine.org/t/only-year-please/1453/8 "2024-04-14T13:47:46Z")

</div>

![image](https://europe1.discourse-cdn.com/flex017/uploads/openrefine/original/1X/b725b1157684107ba2d5e1505ad4b7a84cfd4076.png)

---

<div class="post-metadata">

**Author:** ![thadguidry](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/thadguidry/32/653_2.png) [@thadguidry](https://forum.openrefine.org/u/thadguidry)\
**Post date:** [April 14, 2024, 10:39pm UTC](https://forum.openrefine.org/t/only-year-please/1453/9 "2024-04-14T22:39:24Z")

</div>

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](https://openrefine.org/docs/manual/grelfunctions#todateo-b-monthfirst-s-format1-s-format2-) \<-- What parts in it did not make sense to you? We can improve the docs with your feedback.

[OpenRefine Date functions](https://openrefine.org/docs/manual/grelfunctions#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)

1. use the Cell Edit -\> Common Transforms -\> to Text
2. then use the Cell Edit -\> Common Transforms -\> to Date

---

<div class="post-metadata">

**Author:** ![Kaankale](https://avatars.discourse-cdn.com/v4/letter/k/b9e5f3/32.png) [@Kaankale](https://forum.openrefine.org/u/Kaankale)\
**Post date:** [April 15, 2024, 7:18am UTC](https://forum.openrefine.org/t/only-year-please/1453/10 "2024-04-15T07:18:13Z")

</div>

It worked perfectly!

In the [GREL functions | OpenRefine](https://openrefine.org/docs/manual/grelfunctions#todateo-b-monthfirst-s-format1-s-format2-) I did not realise that it does that for strings.

Was worried that I would have to manually change each row.

Thanks for the patience and step-by-step instructions.

---

<div class="post-metadata">

**Author:** ![tfmorris](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/tfmorris/32/17_2.png) [@tfmorris](https://forum.openrefine.org/u/tfmorris)\
**Post date:** [April 24, 2024, 8:34pm UTC](https://forum.openrefine.org/t/only-year-please/1453/11 "2024-04-24T20:34:03Z")

</div>

> [OpenRefine Date functions](https://openrefine.org/docs/manual/grelfunctions#date-functions) work on Dates or Strings. They do not work on Numbers.

The toDate() function is intended to treat integers as years, so if that's not working, it's a bug.

Tom

---

<div class="post-metadata">

**Author:** ![Gnoeee](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/gnoeee/32/429_2.png) [@Gnoeee](https://forum.openrefine.org/u/Gnoeee)\
**Post date:** [May 30, 2024, 6:20am UTC](https://forum.openrefine.org/t/only-year-please/1453/12 "2024-05-30T06:20:07Z")

</div>

So what about when we have a strings with 2 different formats.. One with the year, month and day and one with only year.

The common transform to dates will give a result like this. How to avoid the adding of -01-01 along with the year.  
 ![image](https://europe1.discourse-cdn.com/flex017/uploads/openrefine/original/2X/7/7daf4e1c9132f9a550b783b432ed29ec7a13bf21.png)

---

<div class="post-metadata">

**Author:** ![thadguidry](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/thadguidry/32/653_2.png) [@thadguidry](https://forum.openrefine.org/u/thadguidry)\
**Post date:** [May 30, 2024, 6:44am UTC](https://forum.openrefine.org/t/only-year-please/1453/13 "2024-05-30T06:44:00Z")

</div>

@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.

Hint: `value.toDate().toString('yyyy')`

---

<div class="post-metadata">

**Author:** ![Gnoeee](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/gnoeee/32/429_2.png) [@Gnoeee](https://forum.openrefine.org/u/Gnoeee)\
**Post date:** [May 30, 2024, 7:57am UTC](https://forum.openrefine.org/t/only-year-please/1453/14 "2024-05-30T07:57:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tfmorris](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.openrefine.org/tfmorris/32/17_2.png) [@tfmorris](https://forum.openrefine.org/u/tfmorris)\
**Post date:** [May 30, 2024, 3:54pm UTC](https://forum.openrefine.org/t/only-year-please/1453/15 "2024-05-30T15:54:00Z")

</div>

> So what about when we have a strings with 2 different formats.. One with the year, month and day and one with only year.
> 
> The common transform to dates will give a result like this. How to avoid the adding of -01-01 along with the year.

OpenRefine doesn't support year-only dates or dates without associated times. The only supported format currently is a fully specified datetime.

Once a string has been parsed into a date, information about the precision of the original string is lost.

Tom
