|
|
|
<?
Function TimeCalculate ($o, $time1, $time2) {
if ($o == '+') {
$a = substr($time1, 0, 1) + substr($time2, 0, 1);
$b = substr($time1, 2, 2) + substr($time2, 2, 2);
if ($b >= 60) {
$a = $a + 1;
$b = $b - 60;
if ($b == 0) {
$b = '00';
}
}
return $a . ":" . $b;
} else if ($o == '-') {
$a_1 = substr($time1, 0, 1);
$b_1 = substr($time2, 0, 1);
$a_2 = substr($time1, 2, 2);
$b_2 = substr($time2, 2, 2);
$a = $a_1 - $b_1;
$b = $a_2 - $b_2;
return $a . ":" . $b;
}
}
echo TimeCalculate ('-','2:50', '1:20');
echo "<br>";
echo TimeCalculate ('+','2:50', '1:20');
// Made By Kjartan Ólason
?> |
|
| A Timing Class Categories : PHP, PHP Classes, Date Time | | | Finding the day of the week for a specific date.
Categories : PHP, Databases, MySQL, Date Time | | | A wrapper function to format dates coming from a databases with the
same syntax as PHP's date() function. Categories : Date Time, Databases, PHP | | | pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes | | | A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function. Categories : PHP, PHP Classes, Calendar, Date Time | | | PHP Round Clock - Must have Gif support to use this. Categories : PHP, Date Time, Graphics | | | A simple and fast calendar combining PHP and tables. Use this as a base for applications in which a calendar is needed. Categories : Date Time, PHP, Complete Programs, Calendar | | | Open and Close your website in fixed times . Categories : PHP, PHP Classes, Cron, Date Time | | | mysql date/time converters Categories : PHP, MySQL, Databases, Date Time | | | Creates three SELECT form fields: Month, Day, and Year. You give it a string which will be used to make the name for the three fields, and a number of seconds to use as the default date. If you give it blank for this value, the current date is used. Categories : HTML and PHP, PHP, Date Time | | | If you want to create select buttons featuring current date this example will show you how... Categories : Date Time, HTML and PHP, PHP | | | Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example. Categories : PHP, Date Time, PHP Classes, Calendar | | | calculus of the eastersunday Categories : BC math, PHP, Date Time, Databases | | | Functions used to define a schedule of holidays. Can define non-fixed holidays (eg. 3rd sunday of June). Categories : Calendar, Date Time, PHP | | | Monthly and Daily Upcoming Events calendar. Categories : Date Time, PostgreSQL, PHP, Calendar, Databases | |
| | | | Christian Seip wrote :571
I needed that before I found this script here, so I`ve written my own functions. I didn`t like the idea "if this is greater than 60 then...".
In case anyone needs it, here`s my two functions:
function TimeToMinutes($timestring)
{
$retval = 0;
if (preg_match("/(\d{1,}):(\d{1,})/", $timestring, $parts))
{
$retval = $parts[1] * 60 + $parts[2];
}
return $retval;
}
function MinutesToTime($minutenstring)
{
$retval = "";
$minuten = $minutenstring % 60;
$stunden = ($minutenstring - $minuten) / 60;
$retval = $stunden . ":" . sprintf("%02d", $minuten);
return $retval;
}
I convert the two time strings to minutes, add them and convert them back. The times are stored as minutes in the database, in order to calculate some statistics via SQL-queries. The format hh:mm is just used for the frontend.
| |
|
|
|