0

Is it possible to convert field entry that has date and time, to only date and check that this value equals TODAY in SQL query?

There is field EntryDate with values like Tuesday, October 04, 2016 12:00 AM - can I somehow convert this to just date, and compare it to equal TODAY?

Thanks

Rain
  • 249
  • 6
  • 14
  • Tag your question with the database you are using. – Gordon Linoff Feb 06 '18 at 14:06
  • 1
    Is `EntryDate` of a proper `timestamp` type? If so, casting to `date` is the first part: https://modern-sql.com/feature/extract#related-cast The other part is comparing it to `current_date`. If `EntryDate` is a string type, you have a bad time ahead :( – Markus Winand Feb 06 '18 at 14:12
  • 3
    This is a trivial variation on this question: https://stackoverflow.com/q/1843395/224704 It should help even if you aren't using SQL Server. If you are using SQL Server, your question can be considered a duplicate. – Disillusioned Feb 06 '18 at 14:13
  • have you tried Convert function ? –  Feb 06 '18 at 14:14

2 Answers2

1

You might be in luck if you are using SQL Server:

    select PARSE('Tuesday, October 04, 2016 12:00 AM' as datetime)

And for the sake of completeness, you can compare to the date part of today's date.

    SELECT
    CASE WHEN PARSE('Tuesday, October 04, 2016 12:00 AM' as datetime) = CONVERT(date, getdate()) THEN 'YES'
    ELSE 'NO' END
Vidmantas Blazevicius
  • 4,652
  • 2
  • 11
  • 30
1

Is it Timestamp? If so then just cast it for Date.

SELECT CAST(tstamp AS DATE)
n0rek
  • 90
  • 1
  • 2
  • 11