Results 1 to 3 of 3

Thread: month to date? [resolved]

  1. #1

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

    Resolved month to date? [resolved]

    Guys

    I need a simple way to get a chunk of 'month to date' data from a sqlserver database?

    I'm currently using:

    MTA.DateCreated between getdate() - (day(getdate()-1) and getdate()

    MTA.DateCreated being a datetime field

    That returns everything from the first of the month but at the current time, not 00:00:00.

    Any clues?

    Peter
    Last edited by thebloke; Mar 24th, 2006 at 12:16 PM. Reason: resolved
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: month to date?

    Cast(Convert(varchar(10),GetDate(),101) as DateTime) will get you today's date without the time.

    Then this will work in your WHERE clause.

    VB Code:
    1. MTA.DateCreated
    2.    between DateAdd(dd,-(DatePart(dd,GetDate())-1),Cast(Convert(varchar(10),GetDate(),101) as DateTime))
    3.      and Cast(Convert(varchar(10),GetDate(),101) as DateTime)

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

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

    Re: month to date?

    Nice one mate, works a treat.
    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