'Odd Behavior from Date.strptime()

I'm doing a date conversion using strptime and it is normalizing my data to always have 2020 as the year and I'm not sure why. Specifically:

value = "2015/03/21"
value2 = Date.strptime(value, '%m/%d/%y')

produces a result where value2 = "2020-03-21" How do I get Date.strptime() to appropriately reflect the year?



Solution 1:[1]

In value year is first, month is second. You want to create date object from string, so to correctly parse you should use correct order:

value = "2015/03/21"
value2 = Date.strptime(value, '%Y/%m/%d')
 => Sat, 21 Mar 2015 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 stolarz