How to calculate last date of this month based on current date?

As i have attached image when i select the date from datepicker and after click on button it must show me the last date of the selected date.

mvp_badge
MVP
Solution

Hi Pooja,


May I propose a different approach?

Instead of reinventing the wheel and rebuilding these kind of date time utility actions, you can use the Date Time Utils forge component.

It has the Month_End function which will get the end of the month given a date, as you can see below.


It has these kind of ready-to-use actions both client and server side.


Kind Regards,
João

Hi Joao,

this is an interesting subject !

I don't yet have a clear idea of what I prefer, how i decide the following question :

When is a function / calculation too simple to bother adding an extra depency to a forge component and when is a function / calculation too complex to 'reinvent the wheel' as you put it.

For me, above formula is so simple that using a forge component feels like too much.

What is your take on this, is it a matter of consistency / best practice to always use from the forge when available, even if you can quickly code it yourself.  Are there any use cases where you would decide to code instead of use from the forge?  

Maybe you have a set of usefull forge components that you don't mind adding as dependency to all your projects because they are super stable and usefull.  If so, can you share some of those besides Date Time Utils you mentioned?

Dorine

mvp_badge
MVP

Hi Dorine,


That's a very fair question.

From my experience, factories tend to grow and multiple applications built and in that regard, functions like the end of the month will probably not be the last utility datetime-related function one will use. Therefore I would prefer to refer to these kind of libraries / toolbox components that will help me down the road.


I would code it when I need to or don't find a forge component that can do it and that I trust the way it's done.

I actually created the Date Time Utils component from needs that an existing component (Extended Date Time, I think) didn't cope, which was client-side functions.

To avoid creating monoliths, I would not create a single module with all the utils, I would prefer to have different applications for different concepts so I would choose / look up a component for the scope I need (for instance, Math Utils, SEO Utils, etc.). 

Yes, but that will be last date of preceding month.

add a month to get last date of the month the testdate is in

so :

AddDays(AddMonths(NewDate(Year(AGivenDate),Month(AGivenDate),1),1),-1)

Hello  Pooja Dusane
You can simply use Built-in functions from OS to calculate it

DateTimeToDate(AddDays(NewDate(Year(CurrDateTime()), Month(CurrDateTime()), 1) , -1))

Hope it was helpful!

Regards,

Tomás Dionísio

Yes, but that will be last date of preceding month.

add a month to get last date of the month the testdate is in

so :

AddDays(AddMonths(NewDate(Year(AGivenDate),Month(AGivenDate),1),1),-1)

Thank you it works

Hi Pooja, Not able to understand your requirement clearly, 'Last date of the selected date' what do you mean by this?

Sachin

Hello Pooja,

Check This URL  

I have attached OML as well  for clarification

Note- Please first select the date in input.


Thanks and Regards,

Akshay Deshpande

datemodification.oml

Hi Akshay,

coding your own logic to determine last day of month is an inferior solution to using built-in functions, I think.

But more importantly, when you code your own logic to determine what is a leap year, make sure it is correct, this won't work for years that are a multiple of 100 but not 400.

Dorine

yes.as you say I had take care of the things of leap year, in that aspect I implement my approach



Ok. I think my approach is wrong but its working fine for me and I will go with that approach only . 

But anyway thanks for feedback.

Thanks for oml it helps me a lot to clear my concepts

Dorine Thanks for your feedback i have modify the things i am just lookinf for 100 years but thanks 

@pooja as i Check my OML helps you please download the new one to see the changes of leap years as well 

Hi Pooja,

Use the built-in functions

Your expression should be like below.


If you want to set this date as default date to your date input, use a local date type variable and set to the date input control and assign the above expression to that local variable at OnInitialize event to the screen.

Let us know if you need anything else.


With Regards,

Sandeep.

mvp_badge
MVP
Solution

Hi Pooja,


May I propose a different approach?

Instead of reinventing the wheel and rebuilding these kind of date time utility actions, you can use the Date Time Utils forge component.

It has the Month_End function which will get the end of the month given a date, as you can see below.


It has these kind of ready-to-use actions both client and server side.


Kind Regards,
João

Hi Joao,

this is an interesting subject !

I don't yet have a clear idea of what I prefer, how i decide the following question :

When is a function / calculation too simple to bother adding an extra depency to a forge component and when is a function / calculation too complex to 'reinvent the wheel' as you put it.

For me, above formula is so simple that using a forge component feels like too much.

What is your take on this, is it a matter of consistency / best practice to always use from the forge when available, even if you can quickly code it yourself.  Are there any use cases where you would decide to code instead of use from the forge?  

Maybe you have a set of usefull forge components that you don't mind adding as dependency to all your projects because they are super stable and usefull.  If so, can you share some of those besides Date Time Utils you mentioned?

Dorine

mvp_badge
MVP

Hi Dorine,


That's a very fair question.

From my experience, factories tend to grow and multiple applications built and in that regard, functions like the end of the month will probably not be the last utility datetime-related function one will use. Therefore I would prefer to refer to these kind of libraries / toolbox components that will help me down the road.


I would code it when I need to or don't find a forge component that can do it and that I trust the way it's done.

I actually created the Date Time Utils component from needs that an existing component (Extended Date Time, I think) didn't cope, which was client-side functions.

To avoid creating monoliths, I would not create a single module with all the utils, I would prefer to have different applications for different concepts so I would choose / look up a component for the scope I need (for instance, Math Utils, SEO Utils, etc.). 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.