LIQUID FOR TECHNICAL MARKETERS: Date Filter & strftime

🗣️ WATCH FULL YOUTUBE VIDEO HERE 🗣

https://youtu.be/AEZz3fNIH24

What’s up everyone, my name is Allan, Founder and Consultant at For Now Marketing, and welcome to LIQUID FOR TECHNICAL MARKETERS!

If your goal is to improve your Liquid coding skills, then please

  1. like this video
  2. subscribe to our channel
  3. watch this video all the way to the end
  4. and keep an eye out for more videos in the future.

Today, we’re going to talk about the Date Filter and… wait… is that a typo in our title?

Just kidding, the second topic is called “sturftime”, or at least that’s how this word seems to be pronounced in the Computer Science community. strftime is short for “string for time”, and strftime will help us flexibly format our ISO 8601 Date variables into so many different formats!

Let’s get started.

New Resource: strftime.net

Before we get started, here’s a new resource that I would like all of you to bookmark, which is strftime.net. I’m constantly referencing this resource to use it as a playground whenever I have a new date format to work with.

You’d think I’d have some of these strftime codes memorized by now, but I really don’t. But why memorize, when we have this resource available to us?

Date Filter

Let’s start by talking about the Date Filter, which we purposely didn’t go over in our videos so far, because it’s such a powerful filter that it deserved its own, entire video.

The Date Filter:

“Converts a timestamp into another date format. The format for this syntax is the same as strftime.”

So the Date Filter works with a timestamp which I will interchangeably call “Date Variable” in this video. By the way, we discussed Date Variables & ISO 8601 in a previous video, so we can be ready to talk about today’s topic!

Let’s look at our first example in Braze. First, we’re going to create a variable called session_first_date and set it equal to 2024–04–30, just the date, in ISO 8601 format. For strftime to work, it’s best if we’re working with ISO 8601 format.

Then, let’s add our Date Filter, and for the parameter, we’re going to type in “%a, %b %d, %y”. Whoa whoa whoa, what the heck are we writing here? That’s not even English!

And that strange looking syntax, “%a, %b %d, %y”, is what we call strftime, or string for time.

Let’s navigate to strftime.net and talk more about how strftime works. I promise this example will make much more sense after this discussion.

How To Use strftime.net

So this is the strftime.net app or playground, and this will be our ultimate, go-to guide whenever we need to figure out how to interpret or write the strftime code for our Date variables.

First, we can actually type in the exact strftime code we saw from the first example, into our textbox here. When we do this, we’ll see exactly how our timestamp is formatted, according to the strftime.

By the way, notice how the timestamp we see is today’s date. On this strftime.net webapp, they will always use the exact current timestamp. So we don’t have the ability to fix the timestamp that they’re working with. That shouldn’t be a problem at all with learning how to use strftime.

Let’s go over some of the time buttons that are provided, broken down by categories. First, we have the year buttons. We see “20 in 2009”, “without century”, and “with century”.

If we click the “Century” button, that means the current year, 2024, will be formatted so that only the 20 part, which represents the Century, will be rendered. Technically, we’re in the 21st century, so I’m not sure if Century was the best name for this, but you get the idea. The first two numbers of the current year will be rendered.

Let me go ahead and clear what we have in the textbox. The next two options are similar, but we have “without century” and “with century”.

If we choose “without century”, that means that the current year, 2024, will be formatted “without century”, so just the 24 part, and if we choose the “with century”, then we’ll see the full 2024 year. Like what you might see in the copyright year in the footer of your emails.

And what’s happening every time we click on any of these format buttons is that the strftime code is being populated inside our textbox. So going back to our Liquid example in Braze. Say we wanted to only render this full year from our Date Variable session_first_date. We simply open up strftime.net, click the year format that we want, copy this code, and this code is what gets placed as a parameter inside our Date Filter.

One thing to remember: this is called strftime, or string for time. It’s a STRING for time. And since the code is a String, the Date Filter Parameters will always be surrounded in quotes.

Let’s take a look at a few more examples.

We have 3 options for Month, and you can see the month-format options here. We have the numeric Month, the shortened word, and the full word. Let’s see what those look like.

2 things to point out here: the numeric month comes with what’s called a leading zero. That means that for single-digit months, like the current month May, this strftime will render as “05” instead of “5”. That 0 in front of the 5 is what we call a leading zero.

For the second and third Month formats, May is unfortunately not the best example to differentiate between a shortened and full Month names. But I will try to remake this video in September to show a better example.

I’ll quickly go over the remaining buttons, although I’ll keep these explanations simple as every button has a clear example that represents how the format works exactly.

We have Weeks, representing which of the 52 weeks today currently is, although I think the first example is broken. But we have two other options: assuming the first week of the year starts on a Sunday or on a Monday.

Quite a few for Days. Shortened word, full word, leading zero number, no leading zero number, day of the week starting from 0 ending in 6, day of the year, and day of the week again starting from 1 ending in 7.

We have some full date formats, so the US-standard month-day-year format, another one called VMS which looks like it stands for multiple things after a quick Google Search, and our favorite: ISO 8601.

We get into the time formats here, so starting with 4 for Hour, 24 hour time with leading zero, 12 hour time with leading zero, 24 hour time with no leading zero, and 12 hour time with no leading zero.

Minute, we just get one option which is nice.

We get a few Second options, Millisecond options, as well as Micro and Nanosecond options, although once again, I’m not sure if all these are working.

Notice that when we choose Second, our rendered time changes. Well, that’s become the current Second of the day is constantly changing, literally every second! So if you ever need a New Years Eve countdown tool, there you have it.

We have uppercase and lowercase AM/PM, some additional time-only formats, your current device’s timezone designator, and the full name of the timezone.

Thank You!

That’s it for today! Make sure to spend some time tinkering around on strftime.net as it can take some time to fully understand what each of the buttons mean.

Thank you for watching, and see you next time!

allan@fornowmarketing.com

fornowmarketing.com

Previous
Previous

LIQUID FOR TECHNICAL MARKETERS: Date Variable & ISO 8601

Next
Next

LIQUID FOR TECHNICAL MARKETERS: Conditionals — if, elsif, else