Find Begining and end dates of the previous month
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Find Begining and end dates of the previous month

  1. #1
    Join Date
    Feb 2011
    Posts
    57

    Find Begining and end dates of the previous month

    Hello,
    I am looking for the formula to find the beginning and end of the previous month. If today is march 28 th then I would like to find february's beginning and end date using the system date.

    When my crystal report runs it will find invoices, from the previous month.

    Post_date between (beginning of February) and {End of February}.

    Post_date is formated as MM/DD/YYYY HH:MM:SS am/pm on the db. I want to check against "MM/DD/YYYY"

    Thank you,
    Pn
    Last edited by PNorm; March 28th, 2011 at 01:09 PM.

  2. #2
    Join Date
    Jul 2005
    Posts
    1,074

    Re: Find Begining and end dates of the previous month

    To calculate the last day of previous month is :
    Code:
    Day(DateSerial(Year(CurrentDate), Month(CurrentDate) , 0))
    The beginning of the month alway is 1

    and use DateValue function, as :

    Code:
    {Table.Field} >= DateValue(Year(CurrentDate), Month(CurrentDate)-1, 1) And 
    {Table.Field} <= DateValue(Year(CurrentDate), Month(CurrentDate)-1, Day(DateSerial(Year(CurrentDate), Month(CurrentDate) , 0))
    )
    JG

  3. #3
    Join Date
    Feb 2011
    Posts
    57

    Smile Re: Find Begining and end dates of the previous month

    Awesome. Thank you worked like a charm.

  4. #4
    Join Date
    Jul 2005
    Posts
    1,074

    Re: Find Begining and end dates of the previous month

    Just be careful when the month is January... need a condition there

    JG

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center