I have a SQL table containing a Date,
Now I want my datepicker to see what the latest date is in the table and then set the defaultdate + 1.
Solved! Go to Solution.
Either of the following can be used to get the max date plus one day:
DateAdd(Date(1970,1,1) + Max(datasource, datefield)/(60*60*24*1000),1,Days)
DateAdd(First(Sort(datasource,datefield,Descending)).datefield,1,Days)
Max isn't delegable, so perhaps stick with the second. Of course, either triggers a query to the database, so perhaps look into using collections, and then using the collection as the datasource.
The first uses the max function, which doesn't return a date, but instead returns the value as the number of milliseconds since 1970, and then calculates the actual date value, and adds one day. The second retrieves the first row based on sorting the table by date, descending, and then adds one day. You can set either of the above as the default for the date picker.
Hi @rvdhorst ,
You could also do this and be completely Delegable (close to option #2 from @Mike2500)
With(
{
wDates:
Sort(
YourTableName,
YourDateField,
Descending
)
},
DateAdd(
First(wDates).YourDateField,
1,
Days
)
)
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
Visit my blog Practical Power Apps
@rho1967 ,
To skip to the next weekday
With(
{
wDates:
Sort(
YourTableName,
YourDateField,
Descending
)
},
DateAdd(
First(wDates).YourDateField,
Switch(
Weekday(
First(wDates).YourDateField
),
6,
3,
7,
2,
1
),
Days
)
)
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
Visit my blog Practical Power Apps
@rho1967 ,
If Saturday is a Work day
With(
{
wDates:
Sort(
YourTableName,
YourDateField,
Descending
)
},
With(
{wDay:First(wDates).YourDateField},
DateAdd(
wDay,
If(
Weekday(wDay) = 7,
2,
1
),
Days
)
)
)
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
Visit my blog Practical Power Apps
Either of the following can be used to get the max date plus one day:
DateAdd(Date(1970,1,1) + Max(datasource, datefield)/(60*60*24*1000),1,Days)
DateAdd(First(Sort(datasource,datefield,Descending)).datefield,1,Days)
Max isn't delegable, so perhaps stick with the second. Of course, either triggers a query to the database, so perhaps look into using collections, and then using the collection as the datasource.
The first uses the max function, which doesn't return a date, but instead returns the value as the number of milliseconds since 1970, and then calculates the actual date value, and adds one day. The second retrieves the first row based on sorting the table by date, descending, and then adds one day. You can set either of the above as the default for the date picker.
Hi @rvdhorst ,
You could also do this and be completely Delegable (close to option #2 from @Mike2500)
With(
{
wDates:
Sort(
YourTableName,
YourDateField,
Descending
)
},
DateAdd(
First(wDates).YourDateField,
1,
Days
)
)
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
Visit my blog Practical Power Apps
Thanks for the nice solutions.
If the day+1 is a Sunday, how can I skip it to Monday (so +2)
@rho1967 ,
To skip to the next weekday
With(
{
wDates:
Sort(
YourTableName,
YourDateField,
Descending
)
},
DateAdd(
First(wDates).YourDateField,
Switch(
Weekday(
First(wDates).YourDateField
),
6,
3,
7,
2,
1
),
Days
)
)
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
Visit my blog Practical Power Apps
Sorry for the confusion. Below an example
Monday+1
Tuesday+1
Wednesday+1
Thursday+1
Friday+1
Saturday+2
How can I make this jump? I was hoping to do a check on wDates.
@rho1967 ,
If Saturday is a Work day
With(
{
wDates:
Sort(
YourTableName,
YourDateField,
Descending
)
},
With(
{wDay:First(wDates).YourDateField},
DateAdd(
wDay,
If(
Weekday(wDay) = 7,
2,
1
),
Days
)
)
)
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
Visit my blog Practical Power Apps
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.
User | Count |
---|---|
199 | |
69 | |
49 | |
48 | |
20 |
User | Count |
---|---|
263 | |
123 | |
85 | |
79 | |
70 |