using date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pieandpeas
    New Member
    • Sep 2007
    • 43

    using date

    I'd like to return items where the date column in a database e.g - (12/08/2007 08:16:00) is less than 30 days from the current date

    any help would be great
  • sourabhmca
    New Member
    • Apr 2007
    • 12

    #2
    Originally posted by pieandpeas
    I'd like to return items where the date column in a database e.g - (12/08/2007 08:16:00) is less than 30 days from the current date

    any help would be great
    hi,

    select <<items_column> > from <<tablename>> where convert(char(10 ),date,101) between convert(char(10 ),getdate()-30,101) and convert(char(10 ),getdate(),101 )

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Originally posted by pieandpeas
      I'd like to return items where the date column in a database e.g - (12/08/2007 08:16:00) is less than 30 days from the current date

      any help would be great
      try:

      Code:
      select * from mytable where datediff(dd, datefieldonyourtable, getdate()) < 30

      Comment

      Working...