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
Subscribe
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).
Recent Posts
- RSS is only dead if we let it die
- Kill your index.php
- 18 Things I Wish I Knew 7 Years Ago
- When does automation become coding
- A list of things you can do to afford Mixergy Premium in 2012
- Thanks Louis now here is my dad
- Your templating engine sucks and everything you have ever written is spaghetti code yes you
- Energy for Opportunity website is now live
- Escaping single and double quotes in XPath queries in PHP
- The reason that outsourcing software is so difficult