locked
i need help in the following "Select * from my table where date = system date" RRS feed

  • Question

  • User273232671 posted

    Hello everybody, this is the first time i post something in here, but going through the other posts showed me that there are very helpfull ppl in here.

     

    Please i need some help in how to write this statement:

    "Select * from mytable where date = system date"

     

    date is a column name of a type datetime in my mytable table, i want to get all the data in that table dated today, but i am having a very hard time solving that, and also another query if i want instead of system date, i want to read from textbox1.text, can any one please help me out, i would really appretiate it alot, and thanx.

    Monday, September 5, 2011 12:44 AM

Answers

  • User-513735053 posted

    Try this

    Select * from mytable where Day(date) = day(getDate()) and Month(date)=Month(GetDate()) and Year(date)=Year(Getdate())

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 5, 2011 1:44 AM
  • User1226526163 posted

    This should work:

     

    SELECT * FROM mytable WHERE date = CONVERT(varchar(10), GETDATE(), 110) 
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 6, 2011 8:54 AM
  • User77042963 posted
    Select * from mytable 
    where [date] >=DATEADD(day, DATEDIFF(day,0,GETDATE()),0) 
    AND [date] < DATEADD(day, DATEDIFF(day,0,GETDATE())+1,0)
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 6, 2011 4:24 PM

All replies

  • User-1367372477 posted

    Hi,

    To Get The SysDate from the DB.

    try used GETDATE()

    SELECT * FROM mytable WHERE data = GETDATE()

    Monday, September 5, 2011 1:21 AM
  • User273232671 posted

    thanx for the reply buddy, but that didnt solve the problem somehow:S

    Monday, September 5, 2011 1:31 AM
  • User-513735053 posted

    Try this

    Select * from mytable where Day(date) = day(getDate()) and Month(date)=Month(GetDate()) and Year(date)=Year(Getdate())

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 5, 2011 1:44 AM
  • User1226526163 posted

    This should work:

     

    SELECT * FROM mytable WHERE date = CONVERT(varchar(10), GETDATE(), 110) 
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 6, 2011 8:54 AM
  • User77042963 posted
    Select * from mytable 
    where [date] >=DATEADD(day, DATEDIFF(day,0,GETDATE()),0) 
    AND [date] < DATEADD(day, DATEDIFF(day,0,GETDATE())+1,0)
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 6, 2011 4:24 PM