Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Date comparison in SQL Server 2008

Posted on 2014-03-04
1
Medium Priority
?
594 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 2000 total points
ID: 39903413
Cast now as a Date.

CAST(GETDATE() AS DATE)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Loops Section Overview

916 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