Got it. That makes sense.
([IS_24H]>0?[HOUR_0_23_Z]:[HOUR_1_12])
I hope I have understood you correctly.
This is possible.
To add one hour.
([IS_24H]>0?(numberFormat("00", ([HOUR_0_23]+1)%24)):(numberFormat("0", ([HOUR_1_12]+1)%12==0?12:([HOUR_1_12]+1)%12)))
Explanation:
([IS_24H]>0? checks if the 24-hour format is active.
- If it is, the expression (numberFormat(“00”, ([HOUR_0_23]+1)%24)) is used:
- [HOUR_0_23]+1 adds 1 hour to the current time.
- % 24 ensures that the time wraps around to 0 when it reaches 24.
- numberFormat(“00”, …) ensures that the time is displayed with a leading zero in the 24-hour format.
If the 12-hour format is active, the expression (numberFormat(“0”, ([HOUR_1_12]+1)%12==0?12:([HOUR_1_12]+1)%12)) is used:
- [HOUR_1_12]+1 adds 1 hour to the current time.
- % 12 ensures that the time wraps around after 11, showing 12 instead of 0.
- ==0?12: handles the special case where the modulo operation results in 0, displaying 12 instead.
- numberFormat(“0”, …) ensures that no leading zero is used for single-digit hours.
To substact one hour
([IS_24H]>0?(numberFormat("00", ([HOUR_0_23]+23)%24)):(numberFormat("0", ([HOUR_1_12]+11)%12==0?12:([HOUR_1_12]+11)%12)))
Why not [HOUR_0_23]-1 or [HOUR_1_12]-1?
Explanation:
[HOUR_0_23] - 1 would directly subtract one hour.
However, it is better to work with modulo, so [HOUR_0_23] + 23 is used instead. This is equivalent to subtracting 1 because (x - 1) is the same as (x + 23) in the modulo-24 system.
The same applies to the 12-hour format.
([IS_24H]>0?[HOUR_0_23_Z]:[HOUR_1_12])
AM/PM
24H
1 Like