View Single Post
  #5  
Old 11-11-2013, 11:12 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: PHP Code in template to use date function?

Here we go, tried to make it easy and spelled out for everyone to grasp completely. I also attached the code in a text file so you could save it and reference later easily.
Code:
<p>What is today's date smarty? <b>{$smarty.now|date_format:$config.Appearance.date_format}</b></p> <p>What month is it smarty? <b>{$smarty.now|date_format:"%B"}</b></p> <p>What day of the month is it smarty? <b>{$smarty.now|date_format:"%e"}</b></p> <p>What day of the week is it smarty? <b>{$smarty.now|date_format:"%A"}</b></p> <p>What year is it smarty? <b>{$smarty.now|date_format:"%Y"}</b></p> <p>Is it November smarty? <b>{if $smarty.now|date_format:"%B" eq "November"}Yes{else}No{/if}</b></p> <p>Is it December smarty? <b>{if $smarty.now|date_format:"%B" eq "December"}Yes{else}No{/if}</b></p> <p>Is it November 1st-9th smarty? <b>{if $smarty.now|date_format:"%B" eq "November" and $smarty.now|date_format:"%e" gte 1 and $smarty.now|date_format:"%e" lte 9}Yes{else}No{/if}</b></p> <p>Is it November 10th-20th smarty? <b>{if $smarty.now|date_format:"%B" eq "November" and $smarty.now|date_format:"%e" gte 10 and $smarty.now|date_format:"%e" lte 20}Yes{else}No{/if}</b></p> <p>Is it December 2nd-10th smarty? <b>{if $smarty.now|date_format:"%B" eq "December" and $smarty.now|date_format:"%e" gte 2 and $smarty.now|date_format:"%e" lte 10}Yes{else}No{/if}</b></p>
Output:
What is today's date smarty? 11-12-2013

What month is it smarty? November

What day of the month is it smarty? 12

What day of the week is it smarty? Tuesday

What year is it smarty? 2013

Is it November smarty? Yes

Is it December smarty? No

Is it November 1st-9th smarty? No

Is it November 10th-20th smarty? Yes

Is it December 2nd-10th smarty? No
Attached Files
File Type: txt smarty-date-tricks.txt (1.2 KB, 89 views)
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote