Skip to main content

Notifications

Power Automate - General Discussion
Answered

Add number of month to a date

Posted on by 13

I have problem with Add to time when adding  for example 6 month. Add to time adds always 30 days resulting in the wrong date in the future. se below

 

using below on 15-04-2019 witll result in 13-10-2019 and not 15-10-20191.png

 

  • robertoz Profile Picture
    robertoz 7 on at
    Re: Add number of month to a date

    Hi All,

    it seems to be fixed already:

    robertoz_0-1604488551567.png

     

  • v-yamao-msft Profile Picture
    v-yamao-msft on at
    Re: Add number of month to a date

    Hi @Assad ,

     

    Thanks for sharing.

     

    It would be helpful for other customers who have the same issue. I really appreciate the workaround you’ve provided.

     

    Hope the issue could be fixed soon.

     

    Best regards,

    Mabel

     

  • Verified answer
    Assad Profile Picture
    Assad 13 on at
    Re: Add number of month to a date

    Hi @v-yamao-msft 

    I tried to do a work arround my self. I am not sure if it could be done in another way but her is the work arround

     

    Step 1 - Insure Leap year for february is it 28 or 29 - it is tested and works fine

    image.png

    if(or(equals(mod(
    int(formatdatetime(variables('Date'),'yyyy')),400),0),
    and(equals(mod(float(int(formatdatetime(variables('Date'),'yyyy'))),4),0),
    not(equals(mod(int(formatdatetime(variables('Date'),'yyyy')),100),0)))),29,28)
     
    Step 2 - adding 3 month as an example
    I used a do until count 3 times. That adds the correct number of days from the month 
    reached in the continiously updated variable "Date".

    image.png

    if(equals(formatdatetime(variables('Date'),'MM'),'01'),'31',
    if(equals(formatdatetime(variables('Date'),'MM'),'02'),variables('Leap'),
    if(equals(formatdatetime(variables('Date'),'MM'),'03'),'31',
    if(equals(formatdatetime(variables('Date'),'MM'),'04'),'30',
    if(equals(formatdatetime(variables('Date'),'MM'),'05'),'31',
    if(equals(formatdatetime(variables('Date'),'MM'),'06'),'30',
    if(equals(formatdatetime(variables('Date'),'MM'),'07'),'31',
    if(equals(formatdatetime(variables('Date'),'MM'),'08'),'31',
    if(equals(formatdatetime(variables('Date'),'MM'),'09'),'30',
    if(equals(formatdatetime(variables('Date'),'MM'),'10'),'31',
    if(equals(formatdatetime(variables('Date'),'MM'),'11'),'30',
    if(equals(formatdatetime(variables('Date'),'MM'),'12'),'31','31'))))))))))))
  • v-yamao-msft Profile Picture
    v-yamao-msft on at
    Re: Add number of month to a date

    Hi @Assad ,

     

    The issue has been reported.

     

    PGs are working on a fix on this issue.

     

    However, I am afraid that there is no easy workaround for this.

     

    Best regards,

    Mabel

     

  • Assad Profile Picture
    Assad 13 on at
    Re: Add number of month to a date

    I created a very ugly logik that do the job. the next step is to beatify the logik. any other ideas is welcome

    1- I need the to find if february is 28 or 29 days 

    image.png

    if(or(equals(mod(int(formatdatetime(variables('Date'),'yyyy')),400),0),
    and(equals(mod(float(int(formatdatetime(variables('Date'),'yyyy'))),4),0),
    not(equals(mod(int(formatdatetime(variables('Date'),'yyyy')),100),0)))),29,28)
     
    2- Adding 3 month as an example
    The idea her is to do until 3 times
    find the correct number of days and updating "Date" until i have my
    final result "Date"
    image.png
    if(equals(formatdatetime(variables('Date'),'MM'),'01'),'31',
    if(equals(formatdatetime(variables('Date'),'MM'),'02'),variables('Leap'),
    if(equals(formatdatetime(variables('Date'),'MM'),'03'),'31',
    if(equals(formatdatetime(variables('Date'),'MM'),'04'),'30',
    if(equals(formatdatetime(variables('Date'),'MM'),'05'),'31',
    if(equals(formatdatetime(variables('Date'),'MM'),'06'),'30',
    if(equals(formatdatetime(variables('Date'),'MM'),'07'),'31',
    if(equals(formatdatetime(variables('Date'),'MM'),'08'),'31',
    if(equals(formatdatetime(variables('Date'),'MM'),'09'),'30',
    if(equals(formatdatetime(variables('Date'),'MM'),'10'),'31',
    if(equals(formatdatetime(variables('Date'),'MM'),'11'),'30',
    if(equals(formatdatetime(variables('Date'),'MM'),'12'),'31','31'))))))))))))

     

  • Assad Profile Picture
    Assad 13 on at
    Re: Add number of month to a date

    Thanks. if not a bug fix maybe a workarround will be nice. I have customer waiting to go online 

  • v-yamao-msft Profile Picture
    v-yamao-msft on at
    Re: Add number of month to a date

    Hi @Assad ,

     

    Thanks for feedback.

     

    The issue could be reproduced by me.

     

    I will help report it and back to you later.

     

    Best regards,

    Mabel

     

  • Assad Profile Picture
    Assad 13 on at
    Re: Add number of month to a date

    Hi @Scott

     

    You have the same issue in your example. you startdate is 22 and the end date is 20

    Her is another exampel from my flow running adding just one month ending with wrong date 13-04 ends as 14-05

    because it adds 31 days when april to may is only 30 days

    2.png

     

  • ScottShearer Profile Picture
    ScottShearer 25,178 on at
    Re: Add number of month to a date

    @Assad 

    It appears as though the issue is with the NextDate and not with the Add to Time action.  Can you post a screen shot from a run that shows the Add to time action.  That will allow you to see the NextDate input.

    AddToTime.jpg

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

October 2024 Newsletter…

October 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #4 How to Conntact Support…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 142,473

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,659

Leaderboard

Featured topics