note 77638 added to ref.datetime

From: Date: Thu, 06 Sep 2007 15:54:57 +0000
Subject: note 77638 added to ref.datetime
Groups: php.notes 
Request: Send a blank email to php-notes+get-130260@lists.php.net to get a copy of this message
I was looking for a solution where I could return the number of days, hours, Minutes and seconds between two entries in a table. DATE_DIFF is not running on my mysql server as my provider uses mysql version 4.0.25 Solution was to use to days and std time functions to calculate the difference in one call. The fields stored in the table(report_table) are time(00:00:00), date(0000-00-00) and record(enum) which tells the app the type of log stored. EG start or end of a report. SELECT (TO_DAYS( end.date ) - TO_DAYS( start.date )) - ( second( end.time ) + (minute( end.time )*60) + (hour( end.time )*3600) < second( start.time ) + (minute( start.time )*60) + (hour( start.time )*3600)) AS days , SEC_TO_TIME( (second( end.time ) + (minute( end.time )*60) + (hour( end.time )*3600) ) - (second( start.time ) + (minute( start.time )*60) + (hour( start.time )*3600) ) ) AS hms, start.time as start, end.time as end FROM report_table AS start , report_table AS end AND start.record = 'Report Begin' AND end.record = 'Report End' LIMIT 1 If there is no end of report then it will not return a result, as you would expect. ---- Server IP: 69.147.83.197 Probable Submitter: 82.46.191.190 ---- Manual Page -- http://www.php.net/manual/en/ref.datetime.php Edit -- https://master.php.net/note/edit/77638 Del: integrated -- https://master.php.net/note/delete/77638/integrated Del: useless -- https://master.php.net/note/delete/77638/useless Del: bad code -- https://master.php.net/note/delete/77638/bad+code Del: spam -- https://master.php.net/note/delete/77638/spam Del: non-english -- https://master.php.net/note/delete/77638/non-english Del: in docs -- https://master.php.net/note/delete/77638/in+docs Del: other reasons-- https://master.php.net/note/delete/77638 Reject -- https://master.php.net/note/reject/77638 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130260) next »