cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
King
Advocate III
Advocate III

add a month to a DateTimePicker

I will explain the case:

 

I have 3 controls:

 

1-Frequency

(DropDow)

[Daily, Monthly, Annual]

 

2-Start date

(DateTimePicker)

 

3-Final date
(DateTimePicker)

 

In the case of Frequency and Initial Date, you can select

 

in the case of End date it is a default value

 

The default value for End Date is:

 

If(
Frequency .Selected.Value = "Daily";
StartDate.SelectedDate + 1
)

 

As you can see I add a day to the Start Date because the selected frequency is Daily

 

Now, how can I add a month or a year to the Start Date in case the Frequency is equal to Monthly or Annual?

1 ACCEPTED SOLUTION

Accepted Solutions
Ajityadav
Frequent Visitor

Hi @King 

you can use this formula in (DefaultDate) property of final date -datetimePicker to set value Dynamically based on the frequency dropdown.

 

If(
    Frequency_dropdown.Selected.Value = "Daily",
    Start_date_picker.SelectedDate + 1,
    Frequency_dropdown.Selected.Value = "Monthly",
    Date(
        Year(Start_date_picker.SelectedDate),
        Month(Start_date_picker.SelectedDate) + 3,
        Day(Start_date_picker.SelectedDate)
    ),
    Frequency_dropdown.Selected.Value = "Annual",
    Date(
        Year(Start_date_picker.SelectedDate)+1,
        Month(Start_date_picker.SelectedDate),
        Day(Start_date_picker.SelectedDate)
    )
)

 


Hope this helps.
If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users to find it.





View solution in original post

4 REPLIES 4
eka24
Super User III
Super User III

Try:

Switch(Frequency.Selected.Value = "Daily";DateAdd(StartDate.SelectedDate + 1);

          "Monthly"; DateAdd(StartDate.SelectedDate + 30);

        "Annual"; DateAdd(StartDate.SelectedDate + 365))
------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Ajityadav
Frequent Visitor

Hi @King 

you can use this formula in (DefaultDate) property of final date -datetimePicker to set value Dynamically based on the frequency dropdown.

 

If(
    Frequency_dropdown.Selected.Value = "Daily",
    Start_date_picker.SelectedDate + 1,
    Frequency_dropdown.Selected.Value = "Monthly",
    Date(
        Year(Start_date_picker.SelectedDate),
        Month(Start_date_picker.SelectedDate) + 3,
        Day(Start_date_picker.SelectedDate)
    ),
    Frequency_dropdown.Selected.Value = "Annual",
    Date(
        Year(Start_date_picker.SelectedDate)+1,
        Month(Start_date_picker.SelectedDate),
        Day(Start_date_picker.SelectedDate)
    )
)

 


Hope this helps.
If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users to find it.





View solution in original post

King
Advocate III
Advocate III

If each month had 30 days, it would have done from the beginning, but some have 31

Ajityadav
Frequent Visitor

Hello @King 

have you tried my solution?
it will definitely work as you wanted to and let me know if you face any issue.
 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors
Users online (2,494)