How to bring the last day of the month?

how to bring the last day of the month?

when you open the page I wish I had come with the last day of the month.

1 Like

I have never tried this so it’s a big guess but start with 1st of month, add 1 month, subtract 1 day. dont even know if it’s possible in Wappler and not near a computer to check.

You can try writing a script for this. I couldn’t find anything in Wappler UI.

Use a little PHP as the Value:

<?php $a_date = "NOW"; echo date('Y-m-t',strtotime($a_date)); ?>

Doesn’t have to be overly complicated.

4 Likes

but he wants the last day if the month, not the current date. that needs a calculation

That is the last day of the current (NOW) month Brian.

https://secure.php.net/manual/en/function.strtotime.php

1 Like

This is cool. Did not know about the ‘t’ format.
Official doc for reference: http://php.net/manual/en/function.date.php

1 Like

apologies, see what you did now, learning even now.

1 Like
<?= date('Y-m-t') ;?>

Hi @AdrianoLuiz,
I tried your code but i get “1978” instead of “2019-11-30” if i take the 2nd of November as current date.

what’s wrong ?

Yes of course you can do this in Wappler - no need for custom php code.

Just use the Wappler formatters, pick the first date of the next month and subtract one day.

I can figure out how to do this in the formater. Can you send a screenshot ?

You can check the docs:

Thank’s George,
In fact i already have read those doc’s and they were helpfull.
I already know how to use formatter to get the first day of the current month like this:
image
or litteraly this:
dmx-bind:value="var1.datetime .getMonth()+'/01/'+var1.datetime .getYear()"
Now, i need to find the llast day of the month.
I did not find any solution starting from var1.datetime, but finaly i have found a solution starting from the previous calculation of the first day of the month:
image

Here is the expression:

var1.datetime.addMonths(1).formatDate("yyyy-MM-01").addDays(-1)

In the formatter it looks like this:

image

I see we had some ordering issues in the formatter that we can improve, but you can also use the expression as stated above.

3 Likes

Top George !

Everything works properly now. .formatDate is very handy !

1 Like

Just found this, and love the simplicity of just changing the dd to 01 to set the start of the month etc. Much easier than trying to subtract certain amount of days or whatever.

A nice way of setting up some filters like “view this month” “view last month” etc

1 Like

you can find last day of month with wappler formatters
just try

{{NOW.formatDate('t-MM-yyyy')}}

No need to type long expressions. you can simply handle it.

result
image

5 Likes

Interesting. How would you do first day of the month? I just thought of a use case where I can use this.

First day of month

{{NOW.formatDate('01-MM-yyyy')}}

image

3 Likes