Results 1 to 4 of 4

Thread: date less x days in SQL[resolved]

  1. #1

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Resolved date less x days in SQL[resolved]

    Guys,

    I'm sure this is straightforward enough but my brain hurts at the moment.

    I want to run a query that gives me data for the last 7 days/month or whatever.

    So I need to do something like:

    select * from tblcounterv3
    where countdate between ('a date a month ago' and convert(varchar,getdate(),103)

    It's the 'a date a month ago' that I don't know how to work out.

    Hope this makes some sense!

    Cheers


    Peter
    Last edited by thebloke; Aug 25th, 2005 at 04:03 AM. Reason: resolved
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: date less x days in SQL

    now-7
    or whatever the equivalent to now is in whichever db you are using...

    1 = 1 day (ish) so a date held as a date (number) minus 1 is yesterdays.

    If you are in vb/vba use the immediates window:
    Code:
    ?clng(cdate("24 Aug 2005"))
    ?cdate(clng(cdate("24 Aug 2005"))-1)

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: date less x days in SQL

    From the Convert I guess you are using SQL Server, which supports DateAdd, eg:

    Code:
    between (DATEADD(month, -1, getdate())  and convert(varchar,getdate(),103)

  4. #4

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Resolved Re: date less x days in SQL

    Thanks chaps, very helpful as always!

    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width