Join the Alteryx Community’s Maveryx Summer Cup event! Compete, network with others, and earn your gold through a series of challenges from July 24th to August 11th. Learn more about the event here.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

how to get the last day of the month

fabs
6 - Meteoroid

Hello, currently I have the below formula. It is formulated in a way that anyone who ran the tool in the specific month, the last day of the current month should show. However, I am just wondering how should I update my formula to show October 31, 2022 as the last day instead of just October 30, 2022. 

 

DateTimeFormat(DateTimeAdd(DateTimeLastOfMonth(),-1,"months"),'%Y-%m-%d')

 

fabs_0-1669281854452.png

 

Thanks for your help in advance!!!

7 REPLIES 7
IraWatt
17 - Castor
17 - Castor

Hey @fabs,

I think you want the datetimetrim function it is the easiest way to get the last day of the month:

IraWatt_0-1669282231827.png

DateTimeTrim(DateTimeNow(),"lastofmonth")

Any questions or issues please ask

Ira Watt
Technical Consultant
Watt@Bulien.com 

 

fabs
6 - Meteoroid

Hi @IraWatt, sorry I meant to say, it was formulated in a way that whoever run the tool, the last day of the month from the day s/he run the tool should show.

 

So for example, today is 11/24/2022, if I run the tool today, it should return a value date of 10/31/2022.

 

ShankerV
17 - Castor

Hi @fabs 

 

Please find the output you are expecting, 

 

I know we can simplify within one formula, but to explain deriving the result, I need to split down as below.

 

 

ShankerV_0-1669282922159.png

 

Formula:

datetimetrim(datetimenow(), "lastofmonth")

DATEADD([Result],-1,"month")

DATEADD([Result],+1,"day")

 

ShankerV_1-1669282948150.png

 

Kindly accept this solution if it provided a solution to your question.

 

Many thanks

Shanker V

 

 

 

IraWatt
17 - Castor
17 - Castor

Ah okay @fabs you can just minus 1 month of the current date then use dattimetrim:

DateTimeTrim(DateTimeAdd(DateTimeNow(),-1,"months"),"lastofmonth")

IraWatt_0-1669283158924.png

 

fabs
6 - Meteoroid

Hi @ShankerV, if my understanding is correct then, that formula will only be applicable to month dates which should end with "31".

 

There are still months which should retain to "30".

ShankerV
17 - Castor

Hi @fabs 

 

The below solution will work for all the months, kindly check from your end too!!!

 

datetimetrim(dateadd(datetimenow(),-1,"months"),"lastofmonth")

 

ShankerV_0-1669283807582.png

 

 

ShankerV_1-1669283819499.png

 

Many thanks

Shanker V

ShankerV
17 - Castor

Hi @fabs 

 

DateTimeFormat(DateTimeAdd(DateTimeLastOfMonth(),-1,"months"),'%Y-%m-%d')

 

Trying to help you on what went wrong in your formula you tried.


1. You took the DateTimeLastOfMonth()
So It takes current month last date which is 30/Nov/2022 - 1month leads to 30/Oct/2022

 

Hence you were not able to reach the result.

 

Many thanks

Shanker V

Labels