imantha
imantha

Reputation: 3838

Converting 2 digit date year in string to a Date Object

Hi I want to convert a 2 digit year date in string format to an Date object. But I an not sure what to use as the format

For 4 digit Dates it works fine, i.e

using Dates 

t1 = "01/01/2017"
Date(t1, "dd/mm/yyyy")

# Out > 2017-01-01

But for 2 digit year

t2 = "27/01/17
Date(t2, "dd/mm/yy")

# Out > 0017-01-27

Any idea what to use as the formatting?

Upvotes: 2

Views: 432

Answers (1)

Antonello
Antonello

Reputation: 6423

This seems not be implemented (yet). See the discussion here or the (open) pull request to implement it here.

It is a debated topic, as the default in other languages is to assign years >68 to the twenty century and those <=68 to the twenty-first century, that is a bit subjective, so the Julia developers preferred to go for the explicit way that the missing digits must be explicitly added.

So for now just add 2000 years:

t2 = "27/01/17"
Date(t2, "dd/mm/yy") + Dates.Year(2000)

Upvotes: 3

Related Questions