Just another tech site

T-SQL DateTime


Current Date

 
DECLARE @CurrentDate DATETIME;
SET @CurrentDate = CAST(@Date as Datetime);

Date Manipulation

-- DEFINE THE LIMITES BASED ON THE      
DECLARE @FirstDayOfYear DATETIME
SET @FirstDayOfYear = DATEADD(yy, DATEDIFF(yy,0,@To), 0)

DECLARE @FirstDayOfMonth DATETIME
SET @FirstDayOfMonth = DATEADD(dd,-(DAY(@To)-1),@To)

DECLARE @LastDayOfMonth DATETIME
SET @LastDayOfMonth = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@To)+1,0))

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Tag Cloud

%d bloggers like this: