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
 Dynamic year based on current date for a WHERE dat

Author  Topic 

jaimealvarez
Starting Member

31 Posts

Posted - 2012-07-26 : 13:50:34
Currently I have a date set like this:

WHERE
(timerate.tkeffdate={ts '2012-01-01 00:00:00'})

But i would like the year on that date to dynamically change based on the year we currently are, so on 1/1/2013 it will change to 2013, th day and month should always stay the same (1/1).

Thans for your help.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-26 : 14:11:46
it should be

WHERE
(timerate.tkeffdate>=DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0)
AND timerate.tkeffdate<DATEADD(yy,DATEDIFF(yy,0,GETDATE())+1,0))


refer below for explanation

http://visakhm.blogspot.com/2010/01/some-quick-tips-for-date-formating.html
http://visakhm.blogspot.com/2012/07/generate-datetime-values-from-integers.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -