Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I want to get only year from a date in asp.net.

Please let me know how to do it?
Posted
Comments
Rajesh Anuhya 6-Jan-11 4:49am    
No Effort...

DateTime.Now.Year
 
Share this answer
 
Hi
string year = DateTime.Now.Year.ToString();
 
Share this answer
 
v2
A Simple Google Search is solve your problem.,

Here[^]

Google is your friend
 
Share this answer
 
Comments
Manas Bhardwaj 6-Jan-11 4:53am    
This (http://lmgtfy.com/?q=c%23+datetime) one might be more appropriate here .:)
Rajesh Anuhya 6-Jan-11 4:55am    
how is this ??? (http://lh6.ggpht.com/_sBjJPChuHmU/TBMR8_PvWAI/AAAAAAAAAb8/c3QUw-TiO7Y/fire.gif)
Rajesh Anuhya 6-Jan-11 6:45am    
How my answer is down voted??
I would start looking up from the documentation[^].

C#
public int GetYearfromDate(string PstrDate)
{
    int LiYear = 0;
    DateTime Lobjdate = Convert.ToDateTime(PstrDate, CultureInfo.InvariantCulture);
    LiYear = Lobjdate.Year;
    return LiYear;
}
 
Share this answer
 
Comments
Manas Bhardwaj 6-Jan-11 7:36am    
Not sure, why my answer has been downvoted :(

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