Customizing Email Content Based on Send Time with AMPscript by Nobuyuki Watanabe

 In the world of email marketing, the ability to tailor content based on the time of send is absolutely crucial. Fortunately, AMPscript swoops in as the hero we all need.

Picture this: morning emails saying “Good morning!” and afternoon emails casually dropping a “Hello!” — all seamlessly executed with the magic of AMPscript.

Behold, a snippet of AMPscript wizardry to dynamically tweak email content based on the time of send:

%%[IF DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') >= 0 
AND DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') < 12
OR DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') >= 24
AND DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') < 36 THEN]%%

<!--- From AM0:00 to PM12:00 --->
Good morning!

%%[ELSE]%%

<!--- From PM12:00 to PM24:00 --->
Hello!

%%[ENDIF]%%
// Template

%%[IF DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') >= 0
AND DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') < 12
OR DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') >= 24
AND DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') < 36 THEN]%%

<!--- From AM0:00 to PM12:00 --->
%%=ContentBlockById("")=%%
%%=ContentImageById("")=%%
Text 1

%%[ELSE]%%

<!--- From PM12:00 to PM24:00 --->
%%=ContentBlockById("")=%%
%%=ContentImageById("")=%%
Text 2

%%[ENDIF]%%

Feel the power! Customize away — add or ditch content, tweak intervals. Use ContentBlockById to pull in all the magic. Oh, and if your image is more of a “simple image data” rebel, it’s ContentImageById, not ContentBlockById. No rebels left behind!

OR DateDiff(‘00:00’,SystemDateToLocalDate(Now()),’h’) >= 24
AND DateDiff(‘00:00’,SystemDateToLocalDate(Now()),’h’) < 36

*By the way, you may have some questions about the above section in the template, but consider this as a formality regarding SystemDateToLocalDate. As for your task, simply adding 24 hours should suffice.

Now, introducing the evening extravaganza with a touch of drama:

%%[IF DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') >= 0 
AND DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') < 12
OR DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') >= 24
AND DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') < 36 THEN]%%

<!--- From AM0:00 to PM12:00 --->
Good morning!

%%[ELSEIF DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') >= 12
AND DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') < 17
OR DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') >= 36
AND DateDiff('00:00', SystemDateToLocalDate(Now()), 'h') < 41 THEN]%%

<!--- From PM12:00 to PM17:00 --->
Hello!

%%[ELSE]%%

<!--- From PM17:00 to PM24:00 --->
Good evening!

%%[ENDIF]%%

There you have it — let this guide be your mischievous companion in the world of email marketing. Go on, give it a whirl! 🚀

Comments

Popular posts from this blog

What are the different Content Blocks in SFMC ?

What is the different email-sending options in SFMC with examples?

Data Extension and List in SFMC