Dates in PHP

12 Dec2006

UPDATE Monday December 27, 2010 21:45 GMT+11: This original post was pretty brief and I've posted in more detail on the same subject

In general, PHP's date handling functions are amazing. You should make yourself familiar with the GNU Date Input formats because they can be used to great effect with strtotime().

Also, the formatting output of the date() function is such that you can usually get any information you need out of a date quite easily. For instance to get the current year, you would do:

PHP date example of getting the current year

To get the previous year you could do:

PHP date exapmle of getting the previous year

This type of date manipulation is a big time saver and it pays to learn it as early as possible.

This entry was posted on Tuesday, December 12th, 2006 at 3:00 pm author iain dooley, php, programming, programmings, best practices

blog comments powered by Disqus

Subscribe

Subscribe via RSS

Building software in the real world - the Working Software blog

We write about our experiences, ideas and interests in business, software and the business of software. We also sometimes write about our own products (in order to promote them).