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
Super User

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

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