Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

First Day of next month

aysha6029
8 - Asteroid

Hi Friends,

 

I am running alteryx workflows based on the dates. i have a scenario, where i want 1st day of next month. for example, if my current date is 09/24/2016 then i need the next month date as 10/01/2016. Please help me to solve this issue,

 

Regards,

Aysha

6 REPLIES 6
JohnJPS
15 - Aurora

Hi @aysha6029

The following will get the first day of the next month for given date field [Date]:

DateTimeAdd(
   DateTimeAdd([Date],1,"months"),
   1 - ToNumber(DateTimeFormat([Date],"%d")),"days")

Basically, it adds one month, then subtracts back based on the day of the month.

 

aysha6029
8 - Asteroid

Thank You. It is working.

Dcurwenreed
6 - Meteoroid

Hi John,

 

I've tried implementing your solution below but i am getting a weird occurrence. For some dates it is working, but for others it isn't. From what i can see the ones it is failing on are those which are the 31st of the month, but again, it isn't failing on all of them, just some. 

 

Success:

* 2017-12-31

* 2018-07-31

* 2016-07-31

 

Fails:

* 2018-03-31

* 2016-10-31

* 2016-03-31

 

(This list isn't exhaustive) but looking at the rest of it, it seems that months of 31 days that are followed by a month with 31 says (July & December) work, but months that aren't (Jan, March, May, October) don't work if the number is the 31st of the month that is being modified. 

 

Is there a solution to this?

 

Thanks

MarqueeCrew
20 - Arcturus
20 - Arcturus

@Dcurwenreed,

 

The question that I would be asking goes like this:  What is the  first day of the next month after the first of this month?

 

That doesn't roll off of the tongue well, but it makes the answer easier to find.  If you FORMAT the "Date" so that it becomes the first day of the month, then 2017-03-31 becomes 2017-03-01.  When you add 1 month to it you get:  2018-04-01.  It doesn't matter if there are 28, 29, 30 or 31 days in this or the next month.  The first is always the first.

 

DateTimeAdd(DateTimeFormat([Date],"%Y-%m-01"),1,"Months")

This formula will format the date to the first and then add 1 month.  It should (will) work for you.

 

Cheers,

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
Dcurwenreed
6 - Meteoroid

Thank you very much. works perfectly! 

Josephine5
5 - Atom
Hello,

How would this work if I needed to return the previous month?

For example if we are in August (08) how do I formulate a column to be last month July (07)
Labels