1

I'm trying to create a condition for my SQL, that shows a 1 if that row reflects today's day.

case when A.EntryDate = GETDATE() then '1' else '0' end as Today

That's accepted but it doesn't show anything but zeros. I've only worked with Access SQL and this one seems to dislike Date()

I've been looking all around for answers and I cannot seem to find one.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
Robit010
  • 63
  • 1
  • 8
  • 1
    Is `EntryDate` a date or datetime? – juergen d Jun 25 '18 at 19:31
  • 2
    Which [DBMS](https://en.wikipedia.org/wiki/DBMS) are you using? "SQL" is just a query language, not the name of a specific database product. Please add the tag for the database product you are using `postgresql`, `oracle`, `db2`, `sql-server`, ... –  Jun 25 '18 at 19:32
  • Possible duplicate of [How to compare only date part when delivery date is today](https://stackoverflow.com/questions/36018833/how-to-compare-only-date-part-when-delivery-date-is-today) – DhruvJoshi Jun 25 '18 at 19:43

1 Answers1

2

The GetDate() method return datetime. To compare today's date you need to convert datetime to date.

case when cast(A.EntryDate as date)  = cast(getdate() as date) then 1 else 0 end
vendettamit
  • 14,315
  • 2
  • 32
  • 54
  • Worth pointing out that DATE was a type added in 2008. For older versions: case when CAST(FLOOR(cast(A.EntryDate as FLOAT) AS DATETIME) = CAST(FLOOR(cast(getdate() as FLOAT)) AS DATETIME) then 1 else 0 end – fritterfatboy Jun 25 '18 at 19:50