Creating a custom date in smarty, using the year from a variable and the month and day of my choosing?

19 Views Asked by At

I'm brand new to this, so go easy on me. I'm trying to pull just the date from the trip start date, use it in a custom date, so that each year, the date I am using in my IF statements doesn't have to be updated.

{$trip->start|date_format:'%Y'}

Will give me the year the trip is taking place. I only want certain information to be included in an email if it is being sent before April 15th of that same year.

{if $smarty.now <= strtotime(INSERT DATE HERE 0415)} 

This is where I need help. How do I get it to pull the year from the trip, then use it to create April 15th of that year, then convert it using strtotime, so I can use it to limit what is sent?

I have tried this:

{assign var="tripyear" value="$trip->start|date_format:'%Y'"}
{if strtotime($trip->start) >= strtotime("$tripyear"0415)}
{if $smarty.now <= strtotime("$tripyear"0415)}

But I have no idea what I'm doing.

1

There are 1 best solutions below

0
Annelies Vaandrager On

The code below assigns the year of the trip to 'tripyear'. It's like you said, but some brackets were missing:

{assign var="tripyear" value="{$trip->start|date_format:'%Y'}"}

If you type this, you will display today's date:

{$smarty.now|date_format}

If you type this, it will display the date of April 15 in the year of $tripyear:

{strtotime("{$tripyear}-04-15")|date_format}

By typing the code below, you will only display the text "hello" if today ($smarty.now) is earlier or on the same date as April 15 in the year of $tripyear.

{if $smarty.now <= strtotime("{$tripyear}-04-15")}
    hello
{/if}