time
Converting To And From Decimal Time In PHP
Mon, 11/29/2010 - 14:00 | by philipnorton42To convert a time value into a decimal value representing the number of minutes can be useful for certain calculations. The following function takes a time as a string of hh:mm:ss and returns a decimal value in minutes.
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.
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
Convert A Date Into Timestamp In JavaScript
Fri, 02/27/2009 - 14:25 | by philipnorton42I have previously talked about using PHP to convert from a date to a time, but what about doing the same in JavaScript?
To get the unix timestamp using JavaScript you need to use the getTime() function of the build in Date object. As this returns the number of milliseconds then we must divide the number by 1000 and round it in order to get the timestamp in seconds.Time Calculator In PHP
Wed, 06/18/2008 - 08:54 | by philipnorton42Use the following function to work out how long it has been since an event in years, months, weeks, days, hours, minutes and seconds.