Some date time questions
1. You have Week no stored in your database and you wanna convert the week no to the corresponding month name
Here is sol
declare @weekno int, @year int
select datename(month,(dateadd(d,((@weekno-1)*7) - (datepart(dw,convert(varchar,@year)+'/1/1')-1),convert(varchar,@year)+'/1/1')))
2. You have Let say month as int in you database and you want to convert it to month name
declare @hello int
set @hello = 4
select datename(month,cast('2008' + '/' + CAST(@hello AS VARCHAR(2)) + '/01' AS DATETIME))
3. You Want to calculate the no of days for a particular year of a particular month
Declare @NoOfDays1 int
Declare @ month1 datetime
set @NoOfDay1 = datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast(cast(year(@month1) as varchar)+'-'+cast(month(@month1) as varchar)+'-01' as datetime))))
4. You have date time stored in database as date and you want to change it to int
Declare @startday as datetime
select CONVERT(INT, Convert(varchar(10),convert(datetime,@Startday),112))
Will add more to the list later...
1. You have Week no stored in your database and you wanna convert the week no to the corresponding month name
Here is sol
declare @weekno int, @year int
select datename(month,(dateadd(d,((@weekno-1)*7) - (datepart(dw,convert(varchar,@year)+'/1/1')-1),convert(varchar,@year)+'/1/1')))
2. You have Let say month as int in you database and you want to convert it to month name
declare @hello int
set @hello = 4
select datename(month,cast('2008' + '/' + CAST(@hello AS VARCHAR(2)) + '/01' AS DATETIME))
3. You Want to calculate the no of days for a particular year of a particular month
Declare @NoOfDays1 int
Declare @ month1 datetime
set @NoOfDay1 = datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast(cast(year(@month1) as varchar)+'-'+cast(month(@month1) as varchar)+'-01' as datetime))))
4. You have date time stored in database as date and you want to change it to int
Declare @startday as datetime
select CONVERT(INT, Convert(varchar(10),convert(datetime,@Startday),112))
Will add more to the list later...
