Dynamics NAV

Wednesday, 24 December 2014

How to get first day and last day of current and previous month

To get the first day of the current month,

  CALCDATE ('<CM-1M+1D>', Today);

To get the Last day of the current month,

    CALCDATE ('<CM>', Today).

To get the first day of the previous month,


     CALCDATE ('<CM-2M+1D>', Today);

To get the Last day of the Previous month,


       CALCDATE('<CM>',CALCDATE('<-CM-1D>',TODAY)). 

10 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. To get the Last day of the Previous month,

    Wrong:
    CALCDATE ('CM-1M', Today).

    Correct:
    CALCDATE('CM',CALCDATE('-CM-1D',TODAY))

    ReplyDelete
    Replies
    1. Yes,you are correct.it was my mistake. Thank you very much.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Best solution in our opinion is:
    Begin and end current month
    CALCDATE('<-CM>') returns first day of current month
    CALCDATE('<CM>') returns last day of current month

    Begin and end previous month
    CALCDATE('<-CM-1M>') returns first day of previous month
    CALCDATE('<-CM-1D>') returns last day of previous month

    Begin and end next month
    CALCDATE('<CM+1D>') returns first day of next month
    CALCDATE('<CM+1D+CM>') returns last day of next month

    Sebastiaan and Ramses

    Edit: Apparantly < and > does not format well.

    ReplyDelete
  6. CALCDATE('CM',CALCDATE('-CM-1D',TODAY)) its worked perfectly

    ReplyDelete

  7. but the thing is if consider the current month as february respective month data is coming but previous month it shows the date from 29-12-2017 to

    31-02-2018

    ReplyDelete
  8. but the thing is if consider the current month as february respective month data is coming but previous month it shows the date from 29-12-2017 to

    31-01-2018 not 31-02-2018

    ReplyDelete
  9. actually the date range of previous month should be 01012017 to 12312017.

    ReplyDelete