Check if date is 2 weeks, 4 weeks, so on. From specific date

Xojo 2022r4.1 on Windows 10
How would I check a date that is selected with webdatepicker to verify that the selected date is 2 weeks, 4 weeks, 6 weeks ect. from a specified date. I want to only allow a date that is on a Friday paydate. Pay is every other Friday. I will supply the starting pay Friday date in my code.
I have not tried any code yet. Was hoping that someone has already solved this.
Thanks

Wouldn’t a (invervalBetweenDatesInDays \ 7) enough ?

Too bad that DateInterval does not offer .TotalDays

@Rick_A
I will try that. But I don’t believe that will solve my issue.
Example, My fixed date will be June 2, 2023 and I need to check if the selected date is exactly 2 weeks, 4 weeks, 6 weeks, 8 weeks and so on, from June 2, 2023. The fixed date will never change.
Maybe that makes sense.
Thanks

Use mod 14 instead. You still need to calculate the IntervalBetweenDatesInDays.


Var baseDate As New DateTime(2023,6,2) // June 2, 2023

Var aDate As New DateTime(2023,6,16) // proper date

Var interv As DateInterval = aDate - baseDate

Var isProper2weeksModFromBase As Boolean = interv.Days mod 14 = 0  // true

Your code doesn’t work if the interval is more than 1 month.

I see. Then


Var baseDate As New DateTime(2023,6,2) // June 2, 2023

Var aDate As New DateTime(2023,6,16) // proper date

Var intervDays As Integer =  aDate.SecondsFrom1970 \ 86400 _
                             - baseDate.SecondsFrom1970 \ 86400

Var isProper2weeksModFromBase As Boolean = intervDays > 0 _
                                           And intervDays mod 14 = 0 // valid date
3 Likes

Rick created a Feature request about the .TotalDays some time ago:

#66479 - DateInterval needs TotalDays and TotalSeconds

2 Likes

That works great. Thank you for all the help.
and Thanks @AlbertoD for your help also.

3 Likes

DateTime also has WeekOfYear so you can just calculate from the current DateTime.Now.WeekOfYear

I don’t know how this will help if:

  • the date is in another year
  • the date selected is not a Friday in the same year (some other calculation needs to be done and not just WeekOfYear

The user is selecting a date with webdatepicker.