PHP/Javascript/HTML DateTime Period Primer Tutorial

PHP/Javascript/HTML DateTime Period Primer Tutorial

PHP/Javascript/HTML DateTime Period Primer Tutorial

Today’s tutorial shows some PHP and Javascript functionality building on a Yahoo Answers question asking about date (difference) functionality using PHP.

There always appear to be lots of functionality in computer languages to do with dates and times, and that is because humans like to know “when” something happened, and because computer languages normally allow for data types to do with Date and, as for this tutorial, DateTime. This division of data types may seem a bit over the top, but quite often in programming, the time component of a DateTime is actually a pest, and we’d much rather deal with a Date object … not so today.

As you code and deal with dates it is good to have sanity checks ready, with websites like Day of the week calendar checker that can make sure your calls have the same understanding as your computer language about concepts like 0 represents Sunday, 1 represents Monday, or that 0 represents January, 1 represents February etcetera, etcetera (ie. sometimes the way we computer types like to start counting at 0 is not always (but is usually) how the software gets designed … you should always try to independently sanity check such crucial issues). Of course, you should try to understand the PHP by looking up the excellent syntax instructions and examples at the home of PHP.

Other funny thing about website date processing is that when you have an interaction with the user you will have to rely on Javascript to keep you right regarding the workings of date related input data. We haven’t catered for every potential bad user input here, in this tutorial (something for you to improve on), and that is why Javascript libraries such as YUI and jQuery have good calendar interfaces, which also have the advantage of looking better.

Thinking about the power of YUI and jQuery libraries makes the job easier, but what this tutorial can help with, is logic and methods to do with date and/or time differences.

Thanks for the tutorial content inspiration go to Famous Dates and Times in History. Obviously, the choices of what is important historically is very subjective, and you may want to tailor your own set of dates and times (this is a hard-coded section of the HTML code as downloadable below.

Other useful tutorials (thanks) helping were:

Here is a link to some downloadable HTML (with Javascript) programming code you could rename to dtdiff.html supervising the downloadable PHP code you could rename to dtdiff.php (called as an iframe within a table).

If this was interesting you may be interested in this too.

This entry was posted in eLearning, Tutorials and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>