Sergey Snegirev
Sergey Snegirev

Reputation: 1026

Formatting a date retrieved from Wikidata

So let's say I have an Infobox template in Wikipedia that retrieves a company foundation date from Wikidata. It contains the following code:

|label7 = Year founded
|text7 = {{wikidata|p571|{{{founded|}}}}}

My problem is that what's retrieved is formatted as 31 January 2010 and it looks weird next to "Year founded' since it is not a year but the whole date. Of course I could rename the label from "Year founded" to "Date founded" and voila, problem solved, right? But I do want to just get the year from Wikidata, not the whole date.

What would be the code for this? I imagine something like {{wikidata|p571[year]|{{{founded|}}}}} or {{wikidata|p571[0]|{{{founded|}}}}} or {{wikidata|p571[YYYY]|{{{founded|}}}}}.

Thanks in advance!

Upvotes: 0

Views: 299

Answers (2)

Tom Morris
Tom Morris

Reputation: 10540

This doesn't sound like a programming question, but it looks like you can request a specific date format as the third parameter to wikidata
https://en.wikipedia.org/wiki/Module:Wikidata#Testing_getValue.2C_getRawValue_and_getDateValue

{{#invoke:Wikidata|getDateValue|P569|FETCH_WIKIDATA|y}}

Upvotes: 3

Vishnu Ranganathan
Vishnu Ranganathan

Reputation: 1355

I highly recomend you to filter the year from date using RegularExpression instead of trying to get only the year.

Upvotes: -2

Related Questions