note 71128 added to function.time

From: Date: Mon, 13 Nov 2006 14:15:07 +0000
Subject: note 71128 added to function.time
Groups: php.notes 
Request: Send a blank email to php-notes+get-119663@lists.php.net to get a copy of this message
Say you want to log start time and end time, and you want to find how many hours it's between them. Step 1. <?PHP $t = time (); $b = date("Y-m-d H:i:s",$t); print $b; //Shows something like this 2006-11-13 14:34:24 ?> Step 2. Create a database and a table. Say you have 2 fields with start time and end time. CREATE TABLE times ( starttime varchar(20) DEFAULT '0000-00-00 00:00:00', endtime varchar(20) DEFAULT '0000-00-00 00:00:00' ); Insert starttime and endtime into your database table. Example starttime: 2006-11-13 14:34:24 endtime: 2006-11-13 16:34:24 Step 3. <?PHP //Connecting to mysql mysql_connect(host,user,password) or die("Unable to connect to database"); @mysql_select_db("yourdatabase") or die("Unable to select database yourdatabase"); $results = mysql_query("SELECT UNIX_TIMESTAMP(endtime)-UNIX_TIMESTAMP(starttime) FROM times"); $s = mysql_result($results,0); print ($s /60) /60; //Will print 2 hours, as result of our examples. ?> ---- Server IP: 62.73.196.231 Probable Submitter: 84.48.183.53 ---- Manual Page -- http://www.php.net/manual/en/function.time.php Edit -- https://master.php.net/note/edit/71128 Del: integrated -- https://master.php.net/note/delete/71128/integrated Del: useless -- https://master.php.net/note/delete/71128/useless Del: bad code -- https://master.php.net/note/delete/71128/bad+code Del: spam -- https://master.php.net/note/delete/71128/spam Del: non-english -- https://master.php.net/note/delete/71128/non-english Del: in docs -- https://master.php.net/note/delete/71128/in+docs Del: other reasons-- https://master.php.net/note/delete/71128 Reject -- https://master.php.net/note/reject/71128 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119663) next »