It's Sean!

UK freelance journalist, author
and writer Sean McManus

Printed from © Sean McManus.
Home > Articles > Webmaster resources > Javascript Toolkit > Javascript examples > Dates

The Javascript smart marketing toolkit

Javascript date handling 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

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");

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(month,day) Displays on screen the number of days remaining until a given date where 0 is January

countdown(11,25); document.write(" until Christmas Day");

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:

Books by Sean McManus

Scratch Programming in Easy Steps

Scratch Programming in Easy Steps

Raspberry Pi For Dummies

Raspberry Pi For Dummies

Learn to program with the Scratch programming language, widely used in schools and colleges.

Set up your Pi, master Linux, learn Scratch and Python, and create your own electronics projects.

Coder Academy

Coder Academy

Cool Scratch Projects in Easy Steps

Cool Scratch Projects in Easy Steps

Learn to make games and other programs in Scratch 2.0, and make a web page in HTML, with this highly interactive book for 7-10 year olds.

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

More books

Recommended articles

Stylised coloured photo of a synth

Discover my music and home recording articles

Interested in starting home recording? Follow me as I start recording, using instruments such as the Novation MiniNova and Korg Kaossilator, and share my synth and sample-based music online.

Scratch cat and rainbow circle

10-block demos for Scratch programming

Lots of people of all ages are learning to program with Scratch. Discover some useful tricks and techniques in my 10-block Scratch demos, including special effects you can drop into your games.

Paper Raspberry Pi case

Download free book chapters and more!

Download a free case for your Raspberry Pi, and free chapters from my books about the Raspberry Pi, Scratch, web design and more!

©Sean McManus.