Finding 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.
To 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.
There 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.
To format the current timestamp in W3C Datetime encoding (as used in sitemap.xml files) use the following parameters.
Use the following function to work out how long it has been since an event in years, months, weeks, days, hours, minutes and seconds.
The easiest (and most reliable) way to store the time in a database table is with a timestamp. It is also the most convenient way of working out time scales as you don't have to do calculations in base 60. In MySQL this is accomplished by the UNIXTIME() function, which can be reversed by using another MySQL function called FROM_UNIXTIME().
However, you can sometimes be left with timestamps in your code and the task of trying to figure out what to do with them.
The first problem is trying to convert a timestamp into a date. So here is a PHP function that does this.