SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tooba
Posting Yak Master

136 Posts

Posted - 04/18/2013 :  00:41:56  Show Profile  Reply with Quote
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

India
52249 Posts

Posted - 04/18/2013 :  01:49:33  Show Profile  Reply with Quote

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


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

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 04/18/2013 :  01:50:08  Show Profile  Reply with Quote
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

136 Posts

Posted - 04/18/2013 :  21:02:44  Show Profile  Reply with Quote
Thanks Visakh...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 04/19/2013 :  02:51:30  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000