SQL to automatically select only current date's rows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mbolan77
    New Member
    • Sep 2006
    • 2

    SQL to automatically select only current date's rows

    Hello...

    I have a table with a number of fields along with a time stamp column... I am wondering how I can query for only rows inserted on the current date other than manually entering the date parameter... An example below:

    Let's say I had a table like this:

    OFF_ID OFFER RESULT ENTRY_TS
    2719 MAGAZINE NOT INTERESTED 2006-09-27 16:11:06.678
    2720 CAR ACCEPT 2006-09-27 16:15:02.231
    2721 VACATION ACCEPT 2006-09-28 08:32:16.547
    2722 T-SHIRT NOT INTERESTED 2006-09-28 08:41:22.812

    I would use the following to get a count of just rows from today:

    SELECT COUNT (*)
    FROM INFO_TABLE
    WHERE INFO_TABLE.ENTR Y_TS > '2006-09-28';

    However, I would like to instead have a query where it automatically pulls rows based on the current date without having to manually enter the date...

    By the way, I am using MySQL against an MS SQL Server Database...

    Thanks in advance for any assistance.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Use CURRENT_DATE. This will do that:
    Code:
    SELECT COUNT (*)
    FROM INFO_TABLE
    WHERE INFO_TABLE.ENTRY_TS > CURRENT_DATE;
    Ronald :cool:

    Comment

    • mbolan77
      New Member
      • Sep 2006
      • 2

      #3
      Thanks for your response, I appreciate it.

      Apparently I'm a moron on 2 counts.. :-)
      1. I'm actually using WinSQL to query the database, not MySQL as I incorrectly noted in my previous post (not sure if that makes a diff)
      2. I tried your suggestion and still can't get it to work (perhaps cuz of #1 above???). I get this message:

      Error: Incorrect syntax near the keyword 'CURRENT_DATE'. (State:37000, Native Code: 9C)

      Any suggestions?

      Thanks again!

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        You'll have to look in your WINSQL manual then to see if a similar function exists. Good luck.

        Ronald :cool:

        Comment

        • ¥Apocalypse¥
          New Member
          • Sep 2008
          • 1

          #5
          mbolan77 Why don't you try using the function getdate() it will give you the actual system date.

          Comment

          Working...