SUMMARY
answer 1 - does not work. after fix, it works, but it is slow, and it fails to work with numeric values. also, it does not support all timezones and daylight savings, nor volatile NOW()
answer 2 - does not answer the question (but explains theory)
answer 3 - requires additional libraries which get outdated, and as 1st one, it requires text strings and volatile NOW()
is a no-no
answer 4 - does not answer the OP question, nor cover DST
answer 5 - does not answer the OP question, but on a right track with covering DST, unfortunately a lot of fixing is required
answer 6 - does not answer the OP question at all
answer 7 - does not answer the OP question, nor cover DST
SHORT ANSWER
yes, you can easily use native formulae to convert timezone with respect to daylight savings
BASELINE
- default GMT (Greenwich Mean Time) does not observe DST (Daylight Saving Time). GMT remains constant throughout the year
- standard PT (Pacific Time) follows DST.
- the start of DST (summer time) for PT is 2nd sunday of march at 2:00 AM (1 hour is added)
- the end of DST (summer time) for PT is 1st sunday of november at 2:00 AM (1 hour is subtracted)
- this applies only for PT as every other timezone will have different ruleset so keep in mind, that it is complicated. for PT, here is the ±5 year distro:
YEAR |
START |
END |
2019 |
10 Mar 2019 02:00 am |
03 Nov 2019 02:00 am |
2020 |
08 Mar 2020 02:00 am |
01 Nov 2020 02:00 am |
2021 |
14 Mar 2021 02:00 am |
07 Nov 2021 02:00 am |
2022 |
13 Mar 2022 02:00 am |
06 Nov 2022 02:00 am |
2023 |
12 Mar 2023 02:00 am |
05 Nov 2023 02:00 am |
2024 |
10 Mar 2024 02:00 am |
03 Nov 2024 02:00 am |
2025 |
09 Mar 2025 02:00 am |
02 Nov 2025 02:00 am |
2026 |
08 Mar 2026 02:00 am |
01 Nov 2026 02:00 am |
2027 |
14 Mar 2027 02:00 am |
07 Nov 2027 02:00 am |
2028 |
12 Mar 2028 02:00 am |
05 Nov 2028 02:00 am |
2029 |
11 Mar 2029 02:00 am |
04 Nov 2029 02:00 am |
LOGIC
a mare timezone offset like -TIME(8, 0, 0)
is not enough to account for DST. to do this the right way, we need to calculate those dates from above, based on a year we are in. the logic is simple. example of equation for start day:
(y &"-"& m &"-"& 1 + 7 * o) - WEEKDAY(y &"-"& m &"-"& 8 - d) + h + {y}
y = year = 2024
m = month = 3 (1-12 ... 3 = march)
o = day in month = 2 (1-4 ... 2 = 2nd sunday)
d = day of week = 1 (1-7 ... 1 = sunday)
h = hour = "2:00"
y = plus one hour = "1:00" (only if calculating start day! otherwise skip!)
some DSTs are based on "last day in month", which can be 4th or 5th in order. equation for that is:
(y &"-"& m + 1 &"-"& 8) - WEEKDAY(y &"-"& m + 1 &"-"& 8 - d) - 7 + h + {y}
after we acquired start and end of DST, we just deploy simple IF
statement:
IF(((A1 + o) >= s) * ((A1 + o) < e), A1 + o, A1 + o - x)
A1 = value (datetime or timevalue) = 2024-06-06 5:00
o = timezone offset between PT summer time and GMT = -"7:00"
s = starting date of PT summer time = 2024-03-10 2:00
e = ending date of PT summer time = 2024-11-03 2:00
x = difference between summer time and winter time = "1:00"
SOLUTION FOR OP
in spreadsheet settings select GMT (no daylight saving)
File > Settings > General > Time zone > (GMT+00:00) GMT (no daylight saving)
this will affect cases when we have times (timevalue) without dates (datevalue)
next, we can use this simple formula:
=BYROW(A20:A30, LAMBDA(a, LET(y,
IF(YEAR(a)=1899, a+LAMBDA(x,x)(TODAY()), a),
s, (YEAR(y)&"-03-15")-WEEKDAY(YEAR(y)&"-03-07")+"3:00",
e, (YEAR(y)&"-11-08")-WEEKDAY(YEAR(y)&"-11-07")+"2:00",
p, y-"7:00", IF(a="",,IF((p>=s)*(p<e), p, p-"1:00")))))
- works only with GMT > PT (for universal solution, continue reading)
- works with single cell
- works with array
- understands DST and timezone
- it's fast and reliable
- it's easy to read and edit
- it's able to adjust DST for date automatically
- no scripts needed
- no libraries needed
- works with datetimes
- works with dates
- works with timevalues
- works with volatile
NOW()
and TODAY()
- utilizes frozen timestamp
LAMBDA(x,x)(TODAY())
no recalculation
- if date is missing it assumes conversion takes place at that moment
- costs nothing
UNIVERSAL SOLUTION
based on this post we can borrow that "side table" from there and adjust the formula accordingly, so we could freely configure our desired timezone with proper DST, all of it in an instant:
=BYROW(A2:A30, LAMBDA(a, LET(y, IF(YEAR(a)=1899, a+LAMBDA(x,x)(TODAY()), a),
i, YEAR(y), m, E3, м, E7, o, LEFT(E4, 1), о, LEFT(E8, 1),
l, o="l", л, о="l", d, TEXT(SEQUENCE(7), "ddd"), p, y+E11,
s, DATE(i, m+l, 1+7*IF(l, 1, o))-WEEKDAY(DATE(i, m+l, 8-XMATCH(E5, d)))-7*l+E6+"1:00",
e, DATE(i, м+л, 1+7*IF(л, 1, о))-WEEKDAY(DATE(i, м+л, 8-XMATCH(E9, d)))-7*л+E10,
IF(a="",, IF((p>=s)*(p<e), p, p-"1:00")))))
RELEVANT