Solved

Date comparison in SQL Server 2008

Posted on 2014-03-04
1
571 Views
Last Modified: 2014-03-04
Hi all.

I have a SQL Server 2008 query as follows:

SELECT     Expired, ExpirationDate
FROM         myTable
WHERE     (ExpirationDate < { fn NOW() })

Open in new window


The problem is, if the expiration date is 2014-03-04 it appears in the results when compared to today. The ExpirationDate field is a date Data Type. What am I doing wrong? Do I need to format NOW()?

Thank you in advance.
0
Comment
Question by:printmedia
1 Comment
 
LVL 15

Accepted Solution

by:
tim_cs earned 500 total points
ID: 39903413
Cast now as a Date.

CAST(GETDATE() AS DATE)
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now