How to convert int into Months

Posted by Raj.Trivedi under Sql Server on 4/3/2013 | Points: 10 | Views : 2108 | Status : [Member] [MVP] | Replies : 4
Hello Team.

I have a table in SQL Server where i am storing Months as integer means


MonthID = MonthNames

1 = January
2 = Feburary
3 = March
4 = April
5 = May
6 = June
7 = July
8 = August
9 = September
10 = October
11 = Novemeber
12 = December

I am fetching data from table what i am trying to do is i want to convert 1 = January
i.e. if in dataset the Monthid is 1 then in the grid it should show as January not 1

Regards,
Raj.Trivedi

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved



Responses

Posted by: Jayakumars on: 4/3/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down

hi

try this without db becos performance issue so try this


public enum GetMontNames
{

January = 1, Feburary = 2, March = 3, April = 4, May = 5, June = 6, July = 7, August = 8, September = 9, October = 10, Novemeber = 11, December = 12
}
protected void bt1_Click(object sender, EventArgs e)
{
string[] values = Enum.GetNames(typeof(GetMontNames));
foreach (string s in values)
{

}

int[] n = (int[])Enum.GetValues(typeof(GetMontNames));
foreach (int z in n)
{

}

}

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

Raj.Trivedi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandeepmhatre on: 4/11/2013 [Member] Starter | Points: 25

Up
0
Down
i think your data design is not proper ,
you should store date in a table instead of Month No:

By using different sql datetime functions you can manipulate the date as a way you want.

Eg: for the month January you need to store 01-01-2013,

with DATENAME Function in sql, you can retrive the JANUARY as Column value.

DATENAME( MONTH , GETDATE())


Sandeep M,
Software Developer
Follow me on :
http://sandeepmhatre.blogspot.in

Raj.Trivedi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Learningtorise on: 4/16/2013 [Member] Starter | Points: 25

Up
0
Down
USE DateName for this purpose:

Syntax:

DATENAME ( datepart , date )

Example :
SELECT DATENAME(month, GETDATE())




http://hashtagakash.wordpress.com/

Raj.Trivedi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandians on: 4/17/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Check It Out!
CREATE TABLE MyTable1

(
MonthID INT IDENTITY(1,1)
)
GO

INSERT MyTable1 DEFAULT VALUES
GO 12

SELECT MonthID, DATENAME(Month,'2013-' + CAST(MonthID AS VARCHAR)+ '-01') [MonthName] FROM MyTable1
GO
Result
MonthID	MonthName

------- ---------
1 January
2 February
3 March
4 April
5 May
6 June
7 July
8 August
9 September
10 October
11 November
12 December


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Raj.Trivedi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response