locked
Where Clause Help RRS feed

  • Question

  • User475570419 posted

    Hello,

    I have a column name CreateDate. I want to create a where clause where I want to show CreateDate is older than 24 hours. Any help is always greatly appreciated.

    Thank you,

    Bob

    Monday, June 27, 2016 2:55 PM

Answers

  • User2103319870 posted

    Nighthawk0712

    I want to create a where clause where I want to show CreateDate is older than 24 hours.

    You can use the DATEAdd function to like given below 

    SELECT CreateDate,*
    FROM YourTableName
    WHERE CreateDate  < DATEADD(hour, -24, GETDATE())

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 27, 2016 3:02 PM

All replies

  • User2103319870 posted

    Nighthawk0712

    I want to create a where clause where I want to show CreateDate is older than 24 hours.

    You can use the DATEAdd function to like given below 

    SELECT CreateDate,*
    FROM YourTableName
    WHERE CreateDate  < DATEADD(hour, -24, GETDATE())

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 27, 2016 3:02 PM
  • User475570419 posted

    I need to add it to the following:

    SELECT "ForumMessages"."CreationDate", "Forums"."ForumID", "ForumMessages"."TopicID", "ForumMessages"."Body"
     FROM   ("Bulletin_Board"."dbo"."ForumMessages" "ForumMessages" INNER JOIN "Bulletin_Board"."dbo"."ForumTopics" "ForumTopics" ON ("ForumMessages"."TopicID"="ForumTopics"."TopicID") AND ("ForumMessages"."UserID"="ForumTopics"."UserID")) INNER JOIN "Bulletin_Board"."dbo"."Forums" "Forums" ON "ForumTopics"."ForumID"="Forums"."ForumID"
     WHERE  "Forums"."ForumID"=19

    Monday, June 27, 2016 3:16 PM
  • User2103319870 posted

    I need to add it to the following:

    Are you facing any issues while adding. You already have and conditions in your query, Just add one more and condition and append the code after where condition

    Monday, June 27, 2016 3:36 PM
  • User475570419 posted

    Thank you for your help.  It worked. I was missing a " in one of the lines.  It work perfectly.

    Monday, June 27, 2016 4:03 PM