A two digit year is a representation of the four number year shown only with the last two digits - for example, 12 being displayed rather than 2012.
Questions tagged [2-digit-year]
39 questions
75
votes
16 answers
Converting a year from 4 digit to 2 digit and back again in C#
My credit card processor requires I send a two-digit year from the credit card expiration date. Here is how I am currently processing:
I put a DropDownList of the 4-digit year on the page.
I validate the expiration date in a DateTime field to be…

Mike Wills
- 20,959
- 28
- 93
- 149
50
votes
6 answers
How to parse string dates with 2-digit year?
I need to parse strings representing 6-digit dates in the format yymmdd where yy ranges from 59 to 05 (1959 to 2005). According to the time module docs, Python's default pivot year is 1969 which won't work for me.
Is there an easy way to override…

blah238
- 1,796
- 2
- 18
- 51
14
votes
1 answer
How to change the base date for parsing two letter years with Java 8 DateTimeFormatter?
If I use a pattern like d/M/yy for creating a Java 8 DateTimeFormatter (e.g. using DateTimeFormatter.ofPattern(pattern); (which I will only use for parsing, not formatting), it will interpret all two-letter years as 20xx, e.g. parsing a string like…

David
- 1,359
- 1
- 13
- 20
13
votes
1 answer
Parsing string to local date doesn't use desired century
I am using this DateTimeFormatter:
DateTimeFormatter.ofPattern("ddMMYY")
I want to parse the string 150790 and I got this error:
Unable to obtain LocalDate from TemporalAccessor: {DayOfMonth=15, MonthOfYear=7,…

Happy
- 1,815
- 2
- 18
- 33
11
votes
5 answers
How to convert two digit year to full year using Java 8 time API
I wish to remove the Joda-Time library from my project.
I am trying to convert a two digit year to full year. The following code from Joda-Time can fulfil the purpose. Below is the following code of joda-time
DateTimeFormatter TWO_YEAR_FORMATTER =…

Deb
- 2,922
- 1
- 16
- 32
9
votes
1 answer
Force 4-digit-year in localized strings generated from `DateTimeFormatter.ofLocalized…` in java.time
The DateTimeFormatter class in java.time offers three ofLocalized… methods for generating strings to represent values that include a year. For example, ofLocalizedDate.
Locale l = Locale.US ;
DateTimeFormatter f = DateTimeFormatter.ofLocalizedDate(…

Basil Bourque
- 303,325
- 100
- 852
- 1,154
6
votes
3 answers
2 digit years using strptime() is not able to parse birthdays very well
Consider the following birthdays (as dob):
1-Jun-68
1-Jun-69
When parsed with Python’s datetime.strptime(dob, '%d-%b-%y') will yield:
datetime.datetime(2068, 6, 1, 0, 0)
datetime.datetime(1969, 6, 1, 0, 0)
Well of course they’re supposed to be…

casr
- 1,166
- 2
- 11
- 17
5
votes
0 answers
How to parse 2-digit years in Java 8 / JSR 310 / threeten.org backport?
This question relates to parsing 2-digit years in Java 8 / JSR 310 / threeten.org backport. 2-digit years are an unfortunate fact-of-life that need to be dealt with.
I am only concerned about the ISO calendar.
JSR 310 by default assumes a "base…

Michael Howard
- 193
- 1
- 8
5
votes
1 answer
Joda Time & parsing two digit year correctly based on pivot
I have the following (somewhat abbreviated) code to parse String input into a Joda Time DateTime object. I need to properly handle multiple formats, including four & two digit years.
setupValidDateFormats();
DateTime date =…

Display name
- 1,109
- 1
- 15
- 31
3
votes
1 answer
Win32: How to prevent DateTimePicker from accepting 2-digit years?
Microsoft's DateTimePicker common control shows ShortDate's according to the configured Locale settings. The customer's computer is configured with a 2-digit year ShortDateFormat (d/M/yy), so the DateTimePicker shows 2-digit years:
When the user…

Ian Boyd
- 246,734
- 253
- 869
- 1,219
3
votes
5 answers
Convert 2 digit year to 4 digit year
How would I convert a 2 digit year formatted like this into four year:
02 -> 2002
87 -> 1987
etc...
What I have so far:
char shortYr[3];
char longYr[5];
scanf("%2s", shortYr);
int shortYrAsInt = atoi(shortYr);
if (shortYrAsInt < 99)
;
How do…

lost_in_the_source
- 10,998
- 9
- 46
- 75
2
votes
1 answer
Throw ValueError for two digit year dates with dateutil.parser.parse
While doing some data cleaning, I noticed that dateutil.parser.parse failed to reject a certain malformed date, thinking that the first number in it is a two digit year. Can this library be forced to treat two digit years as invalid?
Example:
from…

Mihai Todor
- 8,014
- 9
- 49
- 86
2
votes
1 answer
How to calculate current school year based on two-digit starting year?
I am working on a school web project and I need to know the what year a particular student is in from his/her unique registration number.
The registration number looks like UXXEEXXXX, where the first two XX's represent the last two digits of the…

George
- 3,757
- 9
- 51
- 86
1
vote
1 answer
JSON.NET: String '7/1/20 14:15' was not recognized as a valid DateTime
I cannot deserialise a datetime string from Excel using EPPlus. I have read other answers about this but still cannot this to work and get the error: String 'M-d-yy hh:mm' was not recognized as a valid DateTime.
As per other answers a found on this…

Sean
- 11
- 2
1
vote
4 answers
Number date to Alphabetic in awk
I have a file:
ifile.txt
83080603 55 72
87090607 83 87
88010612 82 44
89080603 55 72
00110607 83 87
01030612 82 44
05120618 84 44
The 1st column shows the date and time with the format YYMMDDHH.
I would like to print the first…

Kay
- 1,957
- 2
- 24
- 46