Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date Help

Author  Topic 

tooba
Posting Yak Master

224 Posts

Posted - 2013-04-18 : 00:41:56
Hi Guys,

Need date syntax help.

Here what i want. I have two Variable
Declare @StartDate Datetime
Declare @EndDate Datetime

Set @EndDate = Getdate()
Set @StartDate = ?

What i want for @StartDate, If i run this report today my @StartDate would be 1/1/2013 and @Enddate would be getdate(). If i run same report in Feb/2014 my @StartDate should be 1/1/2014.

Please help me with the syntax.

Thank You in advance.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-18 : 01:49:33
[code]
Declare @StartDate Datetime
Declare @EndDate Datetime

SELECT @StartDate = DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0),@EndDate = DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)

SELECT @StartDate,@EndDate
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-18 : 01:50:08
also see

http://visakhm.blogspot.in/2010/01/some-quick-tips-for-date-formating.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

tooba
Posting Yak Master

224 Posts

Posted - 2013-04-18 : 21:02:44
Thanks Visakh...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-19 : 02:51:30
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -