Please find all the operation done on particular getdate() function,
--Get today date
select getdate()
--Get Day
select DATENAME (DW,GETDATE())
--Get date of sundays in month
declare @d1 datetime, @d2 datetime
--select @d1 = '5/1/2009'
--,@d2= '5/31/2009'
select @d1 = CONVERT(datetime, DATEADD(dd,-(DAY(DATEADD(mm,1,GETDATE()))-1),DATEADD(mm,0,GETDATE())), 103)
,@d2= CONVERT(datetime, DATEADD(d, -DAY(DATEADD(m,1,getdate())),DATEADD(m,1,getdate())), 103)
;with dates ( date )
as
(
select @d1
union all
select dateadd(d,1,date)
from dates
where date < @d2
)
select day(date) as sundaydate from dates where datename(dw,date) = 'Sunday'
--Get total number of days in month
select datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast(cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime))))
--First Day of month
SELECT DAY(DATEADD(dd,-(DAY(DATEADD(mm,1,GETDATE()))-1),DATEADD(mm,0,GETDATE())))
--Last Day of month
SELECT DAY(DATEADD(d, -DAY(DATEADD(m,1,getdate())),DATEADD(m,1,getdate())))
--First Date of month
SELECT CONVERT(VARCHAR(10), DATEADD(dd,-(DAY(DATEADD(mm,1,GETDATE()))-1),DATEADD(mm,0,GETDATE())), 103)
--Last Date of month
SELECT CONVERT(VARCHAR(10), DATEADD(d, -DAY(DATEADD(m,1,getdate())),DATEADD(m,1,getdate())), 103)
--Get date of date
select DAY(getdate())
Thanks
Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Senior Asp.Net Developer
Email: raj143svmit@gmail.com
e-Procurement Technologies Ltd (India)
www.abcprocure.com
1 comment :
thanks
Post a Comment