Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

from a string month = "09/02/2011" how can i extract month and year..pls help
Posted

just convert it into datetime format

C#
DateTime date = Convert.ToDateTime("09 / 02 / 2012");
int month=Convert.ToInt32(date1.Month);
int year=Convert.ToInt32(date1.Year);

In this way, you can get month and year.

Hope this will help you.
And Don't forget to mark as answer if it helps. :)
 
Share this answer
 
Comments
Bojjaiah 8-Feb-12 5:09am    
here not convert like convert.toint32(date1.Month);
you can simply like this

DateTime date = Convert.ToDateTime("09 / 02 / 2012");
int month = date.Month;
int year = date.Year;
Hi,

Just another info.
You can visit this link about the date format http://codeincsharp.blogspot.com/2008/05/different-date-format-in-c.html

Thank You
 
Share this answer
 
v2
Dim dte As DateTime = ddate


Dim month As String = CInt(dte.Month)
Dim year As String = dte.Year
 
Share this answer
 
v2

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