Home Lessons & Videos Site Building Intermediate Date Scripts

Date Scripts

Affilorama members only


Watch a preview Join for free

Date Scripts

2008-09-16 03:23:09

What better way to get your visitors to act now than to give them a deadline? "Act now! This offer expires tomorrow!" In this lesson we look at Date Scripts, the Internet Marketer's best friend.

How can they be used?

You can use a date script to generate a date automatically, without having to go into your HTML every day and change the date yourself. With a few easy tweaks you can make the script generate today's date, yesterday's date, tomorrow's date, or any number of days into the past or future.

This means that no matter when your visitor is looking at your site, the psychological effect of the date is the same. "Oh gosh, that's tomorrow!" or "Wow, this was updated today..."

The code

Try pasting this snippet of code into your web page (make sure you're in "code" view if you're using a WYSIWYG editor):

echo "Order by ".date("jS F Y", mktime(0, 0, 0, date("m"), date("d");+3,

Save this as a .php file (or in an existing PHP file). Because it's a PHP file it's very likely that you won't be able to preview the page on your computer, so you might need to upload it to your website to see it in action.

What you should see is this:

Order by 31st July 2021
echo "Order by ".date("jS F Y", mktime(0, 0, 0, date("m"), date("d")+3,

This date is three days into the future. That's because of the +3 in that line of code above. If you wanted your date to be just one day into the future (and get a more immediate response out of your visitors) then change that little number to a 1 instead of a 3.

Order by 29th July 2021
echo "Order by ".date("jS F Y", mktime(0, 0, 0, date("m"), date("d")+1,

To get today's date, simply drop that little number altogether.

Order by 28th July 2021
echo "Order by ".date("jS F Y", mktime(0, 0, 0, date("m"), date("d"),

Changing the date format

In the above snippet of code, the letters jS F Y determine how the date displays.

  • Lower-case "j" means "Day of the month without leading zeros"
  • Upper-case "S" means "st" "nd" "rd" "th" etc... goes on the end of a number to make "1st" "2nd" "3rd" etc.
  • Upper-case "F" means "A full textual representation of a month, such as January or March"
  • Upper-case "Y" means "A full numeric representation of a year, 4 digits, such as 2008"

To change how the date displays, you just need to change or re-arrange these letters. For a full list of different date format options, there is a useful chart at http://de3.php.net/date.

For PHP to work on your page, you have to save the page as a .php document.

Lesson Summary

In this lesson we looked at how you can use a bit of PHP to dynamically and automatically update relevant dates on your webpage, either to show a page was recently updated, or to give a sense of urgency (e.g. for a purchase). We took a look at:

  • What a date script is useful for
  • The relevant code
  • Changing the format of the date


Learn something new? Share it with your friends!


Questions & Comments + Add a comment


Don't forget to follow us!

More topics

Essential Resources Every New Affilia... New to affiliate marketing? Not sure what it's all about? Then let us get you started!
Affiliate Outsourcing No one person can do everything on their own. Learn how to reduce (or even eliminate!) your workload with outsourcing.
Site Building As an affiliate, chances are you'll end up building a website or two. Here's your basic quickstart!
Marketing Ideas Needing inspiration? Wanting to go outside the box? Take a look in here for your next few marketing ideas!
Market Research for Affiliate Marketers To be a successful affiliate you must learn how to research their market before dedicating your precious time.
Pay Per Click Pay-per-click is one major method affiliates use to get traffic. Learn what it is and how you can use it effectively!
Search Engine Optimization Search engine optimization (SEO) is a major way of getting traffic to your site at minimal cost! Learn how to put it ...
Content Creation This section is all about content: How to write it, how to get it written for you, and other useful goodies!