The Javascript Smart Marketing Toolkit

Javascript date handling toolkit

Photo of a pen poised over a calendar

This is part of the Javascript Smart Marketing Toolkit.

The date handling features of the toolkit can be used to automate seasonal promotions and weekly promotions.

They can also be used to add a bit more life to your copy, by making it respond to the time.

A time-responsive message like "Why not come down tomorrow - we're open until 10pm on a Saturday and it's not too late to phone us today to make a reservation" becomes easy to program. Site visitors can focus on what's relevant now instead of scanning pages of text for the same information.

The time and date used are those set on the visitor's computer, except that the countdown uses Universal Time Coordinated (UTC) time for the dates. Roughly speaking, this is UK time. Given that the countdown is working in days (rather than hours or minutes), this may be accurate enough for use in many other countries.

Table explaining date functions of the toolkit
function what it does example code
the_hour() Returns the hour from the time now (24 hour clock)

if (the_hour()<12) {document.write("Good morning!");} else if (the_hour()<18) {document.write("Good afternoon!");} else document.write("Good evening!");

the_minute() Returns the minute from the time now See example for the_second()
the_second() Returns the second from the time now

document.write("The time is ",the_hour(),":", the_minute(),":",the_second());

the_date() Returns today's date

document.write("Today's date:",day_name(the_day())," ",the_date()," ",month_name(the_month()));

the_day() Returns the day of the week, where 0 is Sunday and 6 is Saturday

if (the_day()==6 || the_day()==0) { document.write("Spoil yourself this weekend!"); } else document.write("Relax - you've been working hard today");

the_year() Returns the year. I needed this for some of the internal code, so I'm exposing it here. I'm not sure how useful it is, compared to the other functions.


day_name() Returns the name of a given day, where 0 is Sunday and 6 is Saturday

document.write("Today is ",day_name(the_day()));

the_month() Returns the month number, where 0 is January and 11 is December

if (the_month()==11) {document.write("Seasons greetings!");}

month_name() Returns the name of a given month, where 0 is January and 11 is December

document.write("This ",month_name(the_month())," why not take a weekend break?");

countdown(year, month, date, event description, message after event happens ) Displays the number of days remaining until a given date (example shown is for a book being published on 27th July 2020). Dates use conventional numbering (1 is January, 12 is December). On day 0, the post-event message is shown. This is good for counting down to a product launch.

countdown(2020, 7, 27, "to publication day!", "This book is out now!");

countdown_recurring(month, date, event description, message for day of event ) Displays the number of days remaining until the next occurrence of a given date (example shown is for Christmas Day). Dates use conventional numbering (1 is January, 12 is December). On day 0, the message for the day of the event is shown. This is good for counting down to anniversaries, birthdays, and holidays that have the same date each year. Using it, you can include a counter on your website that does not need modifying each year.

countdown_recurring(12,25, "to Christmas Day!", "It's Christmas Day! Happy Christmas!");

Cycling banner advert

See the page on banner cycling features of the toolkit for more information on what this is doing and how it works.

Navigating the toolkit:


© Sean McManus. All rights reserved.

Visit for free chapters from Sean's coding books (including Mission Python, Scratch Programming in Easy Steps and Coder Academy) and more!

Discover my latest books

100 Top Tips: Microsoft Excel

100 Top Tips: Microsoft Excel

Power up your Microsoft Excel skills with this powerful pocket-sized book of tips that will save you time and help you learn more from your spreadsheets.

Scratch Programming in Easy Steps

Scratch Programming IES

This book, now fully updated for Scratch 3, will take you from the basics of the Scratch language into the depths of its more advanced features. A great way to start programming.

Mission Python book

Mission Python

Code a space adventure game in this Python programming book published by No Starch Press.

Cool Scratch Projects in Easy Steps book

Cool Scratch Projects in Easy Steps

Discover how to make 3D games, create mazes, build a drum machine, make a game with cartoon animals and more!

Raspberry Pi For Dummies

Raspberry Pi For Dummies

Set up your Raspberry Pi, then learn how to use the Linux command line, Scratch, Python, Sonic Pi, Minecraft and electronics projects with it.



In this entertaining techno-thriller for adults, Sean McManus takes a slice through the music industry: from the boardroom to the stage; from the studio to the record fair.

Scratch and Raspberry Pi resources

Scratch cat with balloons invites you to visit my Scratch resources

Sean's Scratch Resources

Tips, tutorials and free book chapters for Scratch, a coding language widely used in schools.

Four LEDs on a breadboard connected to a Raspberry Pi

Sean's Raspberry Pi Resources

Tutorials and guides for the Raspberry Pi, a budget computer perfect for learning to program.

Walking astronaut from Mission Python book Top | Search | Help | Privacy | Access Keys | Contact me
Home | Blog | Copywriting Services | Books | Free book chapters | Articles | Music | Photos | Games | Shop | About