date
Find A Month From A Given Integer With PHP
Mon, 06/07/2010 - 16:28 | by philipnorton42If you need to know the month from a given integer (from 1 to 12) then you can use the following snippet. This will return the string "Feb".
date("M", mktime(0, 0, 0, 2));
This can be encapsulated into a function call that will take a number between 1 and 12 and return the corresponding string for that month. This function includes some simple error checking to make sure that the number is valid before trying to work out the date.
Advanced Use Of PHP Function strtotime()
Sat, 09/19/2009 - 22:17 | by philipnorton42Finding the next day of the week from a given date can involve some complicated loops and if statements. In PHP it is made quite easy through the use of the strtotime() function. This function, which is part of the PHP core since version 4, can take just about any string representation of the time and convert it into a Unix timestamp.
Google Last Cached Date Finder In PHP
Fri, 09/04/2009 - 12:47 | by philipnorton42When Google looks at a page it takes a snapshot of that page and uses this to match against the query a user entered. To view these cached pages run a Google search and look at the Cached link next to the green URL text of the result. When you view the cached page Google will also give you a date that the page was last cached on. This can be used as a metric of your sites importance as the more often the site is cached, the more favourable Google views your page.
Setting Locale In Zend Framework
Thu, 08/13/2009 - 09:00 | by philipnorton42Every application has a locale, even if that is just the locale of the author. Through the use of locals you can make your application aware of what sort of language, currency and even timezone that the user would like to see. In Zend Framework this is accoumplished via Zend_Locale.
There are many things to do with locale once, but first you need to determine where the user is based. To find this out you simply create a new instance of the Zend_Locale object. The following code will create the Zend_Locale object and print out the language and region of the user.
Convert A String To A Date Value In MySQL
Tue, 04/21/2009 - 13:49 | by philipnorton42There are numerous ways to print out dates and times, and many hours of programming are spent in converting dates from one format to another.
To do this in MySQL you use the STR_TO_DATE() function, which has two parameters. The first parameter is the time to be parsed and the second is the format of that time. Here is a simple example that converts one date format to a MySQL formatted date string.
SELECT STR_TO_DATE('[21/Apr/2009:07:14:50 +0100]', '[%d/%b/%Y:%H:%i:%S +0100]');
This outputs 2009-04-21 07:14:50.
XML Sitemap Date Format In PHP
Fri, 04/03/2009 - 10:49 | by philipnorton42To format the current timestamp in W3C Datetime encoding (as used in sitemap.xml files) use the following parameters.
echo date('Y-m-dTH:i:sP', time());
As of PHP5 you can also use the c format character to print the exact same string.
echo date('c',time());
These would both print out the following:
2009-04-03T11:49:00+01:00