Skip to content

Instantly share code, notes, and snippets.

View nmaratasdev's full-sized avatar

Nolan Maratas nmaratasdev

View GitHub Profile
@nmaratasdev
nmaratasdev / ampscript-datetime-functions-date-part.amp
Created December 14, 2021 20:06
ampscript-datetime-functions-date-part
<!-- Example Code -->
%%[
/**
* Date Part Logic
* Used to isolate specific elements of a date object.
*/
VAR @date, @date_day, @date_month, @date_year, @date_minutes, @date_hours
SET @date = "12/14/2021 9:30:00 AM"
SET @date_day = DatePart(@date,"d")
SET @date_month = DatePart(@date,"m")
@nmaratasdev
nmaratasdev / ampscript-datetime-functions-date-parse.amp
Created December 14, 2021 20:05
ampscript-datetime-functions-date-parse
<!-- Example Code -->
%%[
/**
* Date Parse Logic
* Used to convert a string into a DateTime object.
* Date might be provided as a string in the incorect format so DateParse() converts it into a DateTime object in the proper format.
*/
VAR @date1, @date2, @date3, @date4, @date5
SET @date1 = DateParse("12/14/2021 9:00:00 AM")
SET @date2 = DateParse("December 14, 2017 3:40PM",1)
@nmaratasdev
nmaratasdev / ampscript-datetime-functions-date-diff.amp
Created December 14, 2021 20:05
ampscript-datetime-functions-date-diff
<!-- Example Code -->
%%[
/**
* Date Diff Logic
* Used to return the difference between two date values.
* Always use the DateDiff() when comparing DateTime values otherwise they will be compared as strings.
*/
VAR @date1, @date2, @dateDiff_Days, @dateDiff_Months, @dateDiff_Years, @dateDiff_Minutes, @dateDiff_Hours
SET @date1 = "12/14/2021 9:00:00 AM"
SET @date2 = "12/14/2022 9:00:00 AM"
@nmaratasdev
nmaratasdev / ampscript-datetime-functions-date-add.amp
Created December 14, 2021 20:05
ampscript-datetime-functions-date-add
<!-- Example Code -->
%%[
/**
* Date Add Logic
* Used to increase or decrease date values.
*/
VAR @initialDate, @previousDay, @nextDay, @nextMonth, @nextMinute, @nextHour
SET @initialDate = "12/14/2021 9:00:00 AM"
SET @previousDay = DateAdd(@initialDate,"-1","d") /* Decreases by one day */
SET @nextDay = DateAdd(@initialDate,"1","d") /* Increases by one day */
@nmaratasdev
nmaratasdev / ampscript-datetime-functions-now-triggered-send.amp
Created December 14, 2021 20:04
ampscript-datetime-functions-now-triggered-send
<!-- Example Code -->
%%[
/**
* Now Logic (Triggered Send Workaround)
* Using Now(1) in a triggered send returns the latest TSD published time.
* Add a date field to your triggered DE and name it something like DateAdded.
* Add a default value that auto-populates that new field with current date.
* This captures the date/time the subscriber was added to the triggered DE.
* Use a simple lookup that returns the DateAdded for that subscriber.
*/
@nmaratasdev
nmaratasdev / ampscript-datetime-functions-now-campaign-send.amp
Created December 14, 2021 20:04
ampscript-datetime-functions-now-campaign-send
<!-- Example Code -->
%%[
/**
* Now Logic
* Used to generate a dynamic date at the time of send
*/
VAR @date
SET @date = Now(1)
]%%
<p>%%=v(@date)=%%</p>
@nmaratasdev
nmaratasdev / ampscript-math-functions-beginner-subtract.amp
Last active January 2, 2022 07:21
ampscript-math-functions-beginner-subtract
<!-- Example Code -->
%%[
/**
* Subtract Logic
* The Subtract() is used to subtract two numeric constants.
*/
VAR @number1, @number2, @results
SET @number1 = 2
SET @number2 = 1
SET @results = Subtract(@number1,@number2)
@nmaratasdev
nmaratasdev / ampscript-math-functions-beginner-multiply.amp
Last active January 2, 2022 07:21
ampscript-math-functions-beginner-multiply
<!-- Example Code -->
%%[
/**
* Multiply Logic
* The Multiply() is used to multiply two numeric constants.
*/
VAR @number1, @number2, @results
SET @number1 = 2
SET @number2 = 2
SET @results = Multiply(@number1,@number2)
@nmaratasdev
nmaratasdev / ampscript-math-functions-beginner-mod.amp
Last active January 2, 2022 07:21
ampscript-math-functions-beginner-mod
<!-- Example Code -->
%%[
/**
* Mod Logic
* The Mod() is used to find the remainder between two numeric constants.
*/
VAR @number1, @number2, @results
SET @number1 = 10
SET @number2 = 4
SET @results = Mod(@number1,@number2)
@nmaratasdev
nmaratasdev / ampscript-math-functions-beginner-divide.amp
Last active January 2, 2022 07:21
ampscript-math-functions-beginner-divide
<!-- Example Code -->
%%[
/**
* Divide Logic
* The Divide() is used to divide two numeric constants.
*/
VAR @number1, @number2, @results
SET @number1 = 10
SET @number2 = 5
SET @results = Divide(@number1,@number2)