iOS Question DateUtils.SetDate not incrementing for 26th Oct 2025

db0070

Active Member
Licensed User
Longtime User
I am using DateUtils.SetDate + DateTime.TicksPerDay to increment dates by one. This works through all the dates of a year, but it does not increment when the date is 26th October, 2025. See the code that I have broken up in stages to illustrate the problem. This appears to be associated with the last Sunday of October of any year which is associated with DST. How to resolve this?

DateUtils.SetDate on 26th Oct 2025:
 Dim t1,t2, t3 As Long
 Dim dd_day, dd_mth, dd_year As Int

    t1 = DateUtils.SetDate(2025,10,27)  'Set date to 27th October 2025
    t2 = DateTime.TicksPerDay
    t3 = t1 + t2   'add one day to 27th October
    dd_day = DateTime.GetDayOfMonth(t3) 'The date increments by one to 28th October
    dd_mth = DateTime.GetMonth(t3)
    dd_year = DateTime.GetYear(t3)

    
    t1 = DateUtils.SetDate(2025,10,26) 'Set date to 26th October 2025 (last Sunday of October)
    t2 = DateTime.TicksPerDay
    t3 = t1 + t2   'add one day to 26th October
    dd_day = DateTime.GetDayOfMonth(t3) 'The date remains at 26th October!!
    dd_mth = DateTime.GetMonth(t3)
    dd_year = DateTime.GetYear(t3)
 
Solution
Set date to 26th October 2025 (last Sunday of October)
And what about the last Sunday in October in some countries? That's right, the time change from summer time, to normal time.
I don't know if you are in such a country, but that could be the problem.

This is the description of the SetDate function: Returns the ticks value of the given date (the time will be 00:00:00)

Your problem is caused by the time change.
Use this code instead:
B4X:
    Dim p As Period
    p.Initialize
    p.Days = 1
    Dim t3 As Long = DateUtils.AddPeriod(DateUtils.SetDate(2025,10,26),p)

Alexander Stolte

Expert
Licensed User
Longtime User
Set date to 26th October 2025 (last Sunday of October)
And what about the last Sunday in October in some countries? That's right, the time change from summer time, to normal time.
I don't know if you are in such a country, but that could be the problem.

This is the description of the SetDate function: Returns the ticks value of the given date (the time will be 00:00:00)

Your problem is caused by the time change.
Use this code instead:
B4X:
    Dim p As Period
    p.Initialize
    p.Days = 1
    Dim t3 As Long = DateUtils.AddPeriod(DateUtils.SetDate(2025,10,26),p)
 
Upvote 1
Solution

emexes

Expert
Licensed User
Longtime User
Instead of using ticks values associated with time 00:00 of the date, use ticks value with time 12:00 (or any time that is well clear of the typical DST fixup times of early in the morning).

The DST timing is six months earlier (or later?) for our part of the world, but the issue is still present:

Log output:
01/04/2025 00:00:00    01/04/2025 12:00:00
02/04/2025 00:00:00    02/04/2025 12:00:00
03/04/2025 00:00:00    03/04/2025 12:00:00
04/04/2025 00:00:00    04/04/2025 12:00:00
05/04/2025 00:00:00    05/04/2025 12:00:00
06/04/2025 00:00:00    06/04/2025 11:00:00
06/04/2025 23:00:00    07/04/2025 11:00:00
07/04/2025 23:00:00    08/04/2025 11:00:00
08/04/2025 23:00:00    09/04/2025 11:00:00
09/04/2025 23:00:00    10/04/2025 11:00:00
10/04/2025 23:00:00    11/04/2025 11:00:00
11/04/2025 23:00:00    12/04/2025 11:00:00
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…