Click here to Skip to main content
15,351,641 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i want to convert an integer value into datetime(mmm-yyyy) format can u help?

example: i have integer value :6 now i want to convert this 6 into Jun-2013 How can i convert.
Posted
Comments
Naz_Firdouse 16-Jul-13 2:29am
   
from where you will get the year?

Try:

C#
DateTime dtDate = new DateTime(2013, 6, 1);

 string MonthName= dtDate.ToString("MMMM");
   
In order to have a datetime, you need a minimum of three things: a day, a month, and a year (the time can be inferred to be midnight). You have only one: the month.

So the rest will have to be specified by your application. I suggest you try this:
C#
int myMonth = 6;
int thisYear = DateTime.Now.Year;
DateTime dt = new DateTime(thisYear, myMonth, 1);
   
Comments
vivekpazhani 16-Jul-13 3:15am
   
Hi Thank You So much... i got solution
XML
Try
<pre>DateTime baseDate = new DateTime(1900, 1, 1);
DateTime newDate = baseDate.AddDays(numDays);</pre>
   
More or less the same as above but as extention

C#
public static class Extention
{
    public static string GetMonthAndYear(this int value)
    {
        return new DateTime(DateTime.Now.Year, value, 1).ToString("MMM-yyyy");
    }
}


Then use it like this:

XML
int yourNumber = 6;

yourNumber.GetMonthAndYear();
   

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