Php > Date Time sample source codes
Calculating Time in Php
Calculating Time in Php 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 "
"; echo TimeCalculate ('+','2:50', '1:20'); ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage