Skip to content

Instantly share code, notes, and snippets.

@wvpv
Last active March 8, 2024 16:33
Show Gist options
  • Save wvpv/c3ecc8bf1a51708a815553173e619e51 to your computer and use it in GitHub Desktop.
Save wvpv/c3ecc8bf1a51708a815553173e619e51 to your computer and use it in GitHub Desktop.
Check if date is DST with AMPscript
%%[
set @dateToCheck = "2023-10-25"
set @month = datepart(@dateToCheck, "M")
set @day = datepart(@dateToCheck, "D")
set @daysOfWeek = "SunMonTueWedThuFriSat"
set @dayOfWeekToFind = format(@dateToCheck,"ddd")
set @dayOfWeekNum = divide(add(indexof(@daysOfWeek,@dayOfWeekToFind),2),3)
if @month < 3 or @month > 11 then
set @isDST = 0
elseif @month > 3 and @month < 10 then
set @isDST = 1
else
set @prevSunday = subtract(@day, subtract(@dayOfWeekNum,1))
if @month == 3 then
if @prevSunday >= 8 then
set @isDST = 1
else
set @isDST = 0
endif
else
if @prevSunday <= 0 then
set @isDST = 1
else
set @isDST = 0
endif
endif
endif
output(concat("<hr>dateToCheck: ", @dateToCheck))
output(concat("<br>month: ", @month))
output(concat("<br>day: ", @day))
output(concat("<br>dayOfWeekToFind: ", @dayOfWeekToFind))
output(concat("<br>dayOfWeekNum: ", @dayOfWeekNum))
output(concat("<br>prevSunday: ", @prevSunday))
output(concat("<br>isDST: ", @isDST))
]%%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment