sql query to select a column through date field.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prisesh26
    New Member
    • Sep 2006
    • 29

    sql query to select a column through date field.

    hello friends

    i ve a prob with sql query generation.
    iam doing a project in C# .net. using datagrid iam displaying the entries.for that iam using this query "select posts from tblPost where posteddate ='3/3/2007'
    it dint work properly so even used like functin .. no change .
    can u plz help me out select a field through date

    mainly i ve to write this code in .aspxcs ie in code side.

    ex "select posts from tblpots where posteddate= ' " + datetime.today. date + " '
    this not working

    plz help.
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Have you tried:
    Code:
    select posts from tblpots where posteddate= ' " & date.now() & " '

    Comment

    • prisesh26
      New Member
      • Sep 2006
      • 29

      #3
      thanks keno,

      i tried but its not supporting date.now in c# .. u ve datetime.today. date
      its not working keno.. plz give some more suggestions plz

      Comment

      • NithyaJai
        New Member
        • Mar 2007
        • 18

        #4
        hai,
        try this out...
        i think u vl get.....

        select posts from tblpots where posteddate= ' " getdate() & " '

        Comment

        • Metalzed
          New Member
          • Sep 2006
          • 27

          #5
          I don't think it is the code side that is the problem.


          for that iam using this query "select posts from tblPost where posteddate ='3/3/2007'
          it dint work properly
          First.

          Watch these 2 examples and i think you notice the problem and solution

          I got a table called temp
          Id (int) Date(datetime)
          -----------------------------------------
          1 2007-03-22 05:26:33
          2 2007-03-22 05:26:40
          3 2007-03-22 05:26:47
          that are added by the funktion NOW()
          And
          4 2007-03-22 05:26:33
          that are insert like a string

          Code:
          SELECT     id
          FROM         Temp
          WHERE     (Date = '2007-03-22 05:26:33')
          Result
          -------------------------
          4


          Code:
          SELECT     Date, id
          FROM         Temp
          WHERE     (Date > '2007-03-22 05:26:33') AND (Date < '2007-03-22 05:26:34')
          Result
          -------------------------
          1
          4


          *************** *************** ************
          Simple . The datetime have milliseconds that isn't shown. there for you cant find exact date..

          But what does that have to do with you that uses a date? Simple.

          If the Select query is "Find post between Today and Tomorrow"

          THis is a ugly and bad way to do it but it should work.

          "SELECT id, Date
          FROM Temp
          WHERE (Date > CONVERT(datetim e, CONVERT(varchar (11), { fn NOW() }))) AND (Date < CONVERT(datetim e, CONVERT(varchar (11), { fn NOW() } + 1)))"

          Comment

          Working...