Here is a quick little thing I put together based off of another script I had. This is a bit more condensed and utilizes a For loop instead of a bunch of conditionals.
Below is a commented version of the script to explain what it is doing:
%%[
/* Defines current Date */
set @t = Now()
/* Defines next month (adds a month to current date) */
/* I did it this way to better account for year changes (dec to jan) */
/* and leap years, etc. */
set @nm = DateAdd(@t,1,'M')
/* Grabs the month part of the new date */
set @nmMonth = DatePart(@nm,'M')
/* Grabs the year part of the new date */
set @nmYear = DatePart(@nm,'Y')
/* Creates a new date by combining month with 01 and year via Concat */
set @fonm = DateParse(CONCAT(@nmMonth,'/01/',@nmYear))
/* Grabs the day name from first of next month date */
set @fonmDay = FormatDate(@fonm,'ddddd')
/* String created to be used as rowset to find day index to next thursday for new month */
set @dayStr = "Thursday|Friday|Saturday|Sunday|Monday|Tuesday|Wednesday"
/* Turn above string into rowset */
set @dayRS = BuildRowsetFromString(@dayStr,'|')
/* For loop to iterate through new rowset */
for @i=1 TO Rowcount(@dayRS) DO
/* Sets row to look at based on iterative (@i) */
set @row = Row(@dayRS,@i)
/* Sets the field to display, in this we use ordinal as there is no column name */
set @day = Field(@row,1)
/* Use a conditional to check if the days match */
if @fonmDay == @day then
/* Once they match, you set the 'index' to equal 8 minus the iterative */
/* I chose 8 so that if it is Wednesday (iterative 7) we get 1 */
/* to add a single day, etc. */
set @index = Subtract(8,@i)
/* Conditional that if index is greater than 6, to set to 0 */
/* This will account for if the first is a Thursday */
if @index > 6 then
set @index = 0
endif
endif
next @i
/* Add together the index to the first of the next month to get first thursday */
set @firstThurs = DateAdd(@fonm,@index,'D')
]%%
%%=v(@firstThurs)=%%
Below is the cleaned up version without comments:
%%[
set @t = Now()
set @nm = DateAdd(@t,1,'M')
set @nmMonth = DatePart(@nm,'M')
set @nmYear = DatePart(@nm,'Y')
set @fonm = DateParse(CONCAT(@nmMonth,'/01/',@nmYear))
set @fonmDay = FormatDate(@fonm,'ddddd')
set @dayStr = "Thursday|Friday|Saturday|Sunday|Monday|Tuesday|Wednesday"
set @dayRS = BuildRowsetFromString(@dayStr,'|')
for @i=1 TO Rowcount(@dayRS) DO
set @row = Row(@dayRS,@i)
set @day = Field(@row,1)
if @fonmDay == @day then
set @index = Subtract(8,@i)
if @index > 6 then
set @index = 0
endif
endif
next @i
set @firstThurs = DateAdd(@fonm,@index,'D')
]%%
%%=v(@firstThurs)=%%
To change which day name you want to grab, you would just adjust the string to begin with that day instead of Thursday and then list out the rest in order. So for instance, for the first friday, all you would have to change is the dayStr value.
From: "Thursday|Friday|Saturday|Sunday|Monday|Tuesday|Wednesday"
To: "Friday|Saturday|Sunday|Monday|Tuesday|Wednesday|Thursday"
and the script will now look for the first Friday instead.
@
andFirstthursday
(just use@Firstthursday
) and see if it helps?