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
 Check if today's date is between two date values

Author  Topic 

mavericky
Posting Yak Master

117 Posts

Posted - 2011-04-25 : 19:42:45
Hi All,
I have a table which has 6 columns, out of which last 2 are start date and end date. As part of my stored procedure, I have written a select statement that will fetch me all the parameters of the table. I also want to check if the current date falls between the 'Start Date' and 'End Date' column values and return true if it does else return false. Can anyone please tell me how can I achieve this in the same stored procedure?

Thanks in anticipation,
Mavericky

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-04-25 : 20:05:50
[code]
SELECT . . . .
case when start_date <= dateadd(day, datediff(day, 0, getdate()), 0)
and end_date >= dateadd(day, datediff(day, 0, getdate()), 0)
then 'TRUE'
else 'FALSE'
end
FROM yourtable
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Haz.vali
Starting Member

3 Posts

Posted - 2011-04-26 : 02:00:54
CREATE PROCEDURE Product
as
begin

select * , case when getdate() between S_date and End_date
then 'TRUE'
else 'FALSE'
end as DATE_MATCH from dbo.Product_Sales

end
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-04-26 : 05:37:43
quote:
Originally posted by Haz.vali

CREATE PROCEDURE Product
as
begin

select * , case when getdate() between S_date and End_date
then 'TRUE'
else 'FALSE'
end as DATE_MATCH from dbo.Product_Sales

end


See Tan's query and also this link
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/21/understanding-datetime-column-part-iii.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

mavericky
Posting Yak Master

117 Posts

Posted - 2011-04-26 : 11:26:53
Thanks a lot everyone!!! Your solutions worked.

My problem is solved.

Mavericky
Go to Top of Page
   

- Advertisement -