Hi all.
How do I convert string format month int numbered month.
For example how do i convert "Apr" into 05, or "Jan into 01.
Thanks in advance.
Alps
Converting short date format text to numbered month
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Realgar22 pointsPosted Aug 25, 2005, 4:25 AM EDT
{
switch (month)
{
case "Jan":
return 1;
break;
case .....
...
case "Dec":
return 12;
break;
default:
return null;
break;
}
}
alps2 pointsPosted Aug 25, 2005, 6:40 AM EDT
However I was thinking if a method already exists in the .NET classes,
may be in the DateTime classes somewhere.
Realgar22 pointsPosted Aug 25, 2005, 8:32 AM EDT
string stringmonth = "Feb"; //or whatever you wish
int month = Convert.ToDateTime("01/"+stringmonth+"/2005").Month;
I think the first method was better though.
I´m not sure if there are other ways.