Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
I want to get only the last two digits of present year.
e.g. if present year is 2011 then I want only "11", using DateTime structure in C#.
Posted
Updated 13-Jul-16 8:56am
v2

Try:
DateTime dt = DateTime.Now;
Console.WriteLine(dt.ToString("yy"));
 
Share this answer
 
Comments
Nuri Ismail 8-Apr-11 5:21am    
Good and very quick answer, my 5. :)
Sergey Alexandrovich Kryukov 9-Apr-11 0:04am    
As simple as that, a 5.
--SA
I'd do it like this:

var year = DateTime.Now.ToString("yy");
 
Share this answer
 
Comments
Rojeh 8-Apr-11 7:13am    
my 5 :)
Sergey Alexandrovich Kryukov 9-Apr-11 0:04am    
Same time I guess? A 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900