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
 Dynamic year based on current date for a WHERE dat
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jaimealvarez
Starting Member

29 Posts

Posted - 07/26/2012 :  13:50:34  Show Profile  Reply with Quote
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

India
47173 Posts

Posted - 07/26/2012 :  14:11:46  Show Profile  Reply with Quote
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
  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.03 seconds. Powered By: Snitz Forums 2000