# How to write a condition correctly

How can you write a condition to output

1.   (BeginDate) First day of last month

2.   (EndDate) Last day of last month

For me "BeginDate" displays correctly, but "EndDate" incorrectly displays the last day of the last month

1))

Hi kabdygazinov,

You need to create a logic for getlastdate of month because month last date can be 31,30,29 or 28.

SO you can set month first date but directly can not set last date .

Find the attched oml that will help you to get month last date.

Regards

Rahul Sahu

Hi kabdigazynov,

you don't really need to build the formula for finding leap years and such, you can just do following

`FirstOfMonth = NewDate(Year(SomeDate),Month(SomeDate),1)`
`LastOfMonth = AddDays(AddMonths(FirstOfMonth,1),-1)`

basically, add a month to the first day, which brings you to the first day of the next month, then substract a day.

Dorine

PS @Rahul, your formula is not correct for years that are a multiple of 100 but not a multiple of 400.  (for example february of 2100)

Cool @Dorine Boudry ,

Your solution work if only pass First Date of Month otherwise it will not return last date of month

Dorine Boudry wrote:

Hi kabdigazynov,

you don't really need to build the formula for finding leap years and such, you can just do following

`FirstOfMonth = NewDate(Year(SomeDate),Month(SomeDate),1)`
`LastOfMonth = AddDays(AddMonths(FirstOfThatMonth,1),-1)`

basically, add a month to the first day, which brings you to the first day of the next month, then substract a day.

Dorine

PS @Rahul, your formula is not correct for years that are a multiple of 100 but not a multiple of 400.  (for example february of 2100)

Sorry for the stupid question. The formula must be added to "Run Server Action (AgreementPeriod)" or Assign (in the Screen in my question

There's no stupid questions.

Where is the date coming from for which you need the month boundaries.  From the list you are iterating with the ForEach ?  Then you should assign BeginDate and EndDate within that cycle of course.

And where will you make use of them ? Inside the server action AgreementPeriod ?  As filter in the GetApplications.  The assigns should happen before you need them.

Rahul Sahu wrote:

Cool @Dorine Boudry ,

Your solution work if only pass First Date of Month otherwise it will not return last date of month

can you give an example ?

Oh, do you mean, the second assign only works after the first ??  Right, of course, I assumed both would happen in same assign.  If you only need the Last Day of Month, you can just compress that into a single assign

`AddDays(AddMonths(NewDate(Year(SomeDate),Month(SomeDate),1),1),-1)`

Dorine

So the output parameters of agreementPeriod are a begindate and enddate ?

So what else happens inside that server action besides setting those 2 dates ?  Can you show logic of that.  Really it is up to you right, you can choose where you determine those 2 dates, as long as it is after determining for what date you need them and before using them.

I guess U use them as filter in the GetApplications aggregate ??

Dorine Boudry wrote:

So the output parameters of agreementPeriod are a begindate and enddate ?

So what else happens inside that server action besides setting those 2 dates ?  Can you show logic of that.  Really it is up to you right, you can choose where you determine those 2 dates, as long as it is after determining for what date you need them and before using them.

I guess U use them as filter in the GetApplications aggregate ??

I am taking data from an aggregate. BeginDate - first day from the last month

EndDate -  is the last day of the last month

kabdygazinov wrote:

Why does the program give me an error that - "Unknown object "SomeDate" in expression?

Hi,

Somedate is just an example, i don't know for what date you want to do this.  For what month do you want to get the first and last day.  Is that this month, than you would use Currdate() instead of SomeDate.  If it is for some month in the past, maybe for a given date from your database, then you need to use that date from the database.

Dorine Boudry wrote:

kabdygazinov wrote:

Why does the program give me an error that - "Unknown object "SomeDate" in expression?

Hi,

Somedate is just an example, i don't know for what date you want to do this.  For what month do you want to get the first and last day.  Is that this month, than you would use Currdate() instead of SomeDate.  If it is for some month in the past, maybe for a given date from your database, then you need to use that date from the database.

it should every month display data from the last month

Can you open oml?

kabdygazinov wrote:

Can you open oml?

you still have to share it in this forum thread

You can do with CHOOSE FILE button under here

Solution

kabdygazinov wrote:

it should every month display data from the last month

Ok, so today it should show data for June ?  In that case :

First day of previous month is one month earlier than first day of this month

`FirstDay = AddMonths(NewDate(Year(CurrDate()),Month(CurrDate()),1),-1)`

Last day of previous month is one day earlier than first day of this month

`LastDay = AddDays(NewDate(Year(CurrDate()),Month(CurrDate()),1),-1)`

Solution

kabdygazinov wrote:

Dorine Boudry wrote:

kabdygazinov wrote:

Can you open oml?

you still have to share it in this forum thread

You can do with CHOOSE FILE button under here

nope, that doesn't work