473,785 Members | 2,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with PHP & SQL code, new to this.

JA
I am trying to pull a time stamp out of a database,looks like this
2004-06-24 10:12:03 . Then I need to substring it so that I can take
a difference of 2 times. Basically I making a clock in/clock out
script for my job. But I can't figure out the query and then how to
substring the time so that I can do math with just the time part and
not the date. Or if you guys/gals no if any code out there, were
someone has written a script like this, that would be great. I am
willing to send my code if you need it. It should be easy to code,
but i've never done PHP before. Thanks in advance.

Jimmy Allen
Jul 17 '05 #1
3 1853
On 24 Jun 2004 09:59:05 -0700, ji*********@hot mail.com (JA) wrote:
I am trying to pull a time stamp out of a database,looks like this
2004-06-24 10:12:03 . Then I need to substring it so that I can take
a difference of 2 times.

You can find the difference between two timestamps with a select from
the database.
Something like elect t_start, t_end, time_format((t_ start - t_end),
'%H:%M%S) from testtab;

But I can't recall how to convert the hours (1 hr = 100, not 60)

You can also select each part of the timestamp into its own slot:
mysql> select extract(year from t_start) ys, extract(year from t_end)
ye, extract(month from t_start) ms from testtab;

Long but it works.
+------+------+------+------+------+------+
| ys | ye | ms | me | ds | de |
+------+------+------+------+------|------|
| 2004 | 2004 | 1 | 2004 | 2004 | 1 |
+------+------+------+------+------+------+
--
gburnore@databa six dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
| ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
| ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
Black Helicopter Repair Svcs Division | Official Proof of Purchase
=============== =============== =============== =============== ===============
Want one? GET one! http://www.databasix.com
=============== =============== =============== =============== ===============
Jul 17 '05 #2
JA wrote:
I am trying to pull a time stamp out of a database,looks like this
2004-06-24 10:12:03 . Then I need to substring it so that I can take
a difference of 2 times. Basically I making a clock in/clock out
script for my job. But I can't figure out the query and then how to
substring the time so that I can do math with just the time part and
not the date.


Hi Jimmy,

Why do you need to ignore the date - you could confuse the issue if you
have people working over the midnight hour. Why not just do the math on
the whole date/time string.

Extract the data from the database, using something like:
SELECT login_time from tbl_whatever;
SELECT NOW();

- assigning each to a variable within your script. I've hardcoded the
date/time string below for ease, but you would populate them using the
queres above. Using NOW() will give you the current time from the MySQL
server.

run your two dates through a function which does this:
<?php
$time1 = strtotime("2004-06-01 07:30");
$time2 = strtotime("2004-06-01 18:32");

$interval = $time2 - $time1;

echo "The time difference is : {$interval} seconds<br>";
echo "which equates to : ".strftime("%H: %M", $interval);

?>

Hope this helps, regards,

Andy

Jul 17 '05 #3
JA wrote:
I am trying to pull a time stamp out of a database,looks like this
2004-06-24 10:12:03 . Then I need to substring it so that I can take
a difference of 2 times. Basically I making a clock in/clock out
script for my job. But I can't figure out the query and then how to
substring the time so that I can do math with just the time part and
not the date. Or if you guys/gals no if any code out there, were
someone has written a script like this, that would be great. I am
willing to send my code if you need it. It should be easy to code,
but i've never done PHP before. Thanks in advance.

Jimmy Allen


From the MySQL Docs:

TIMEDIFF(expr,e xpr2)
TIMEDIFF() returns the time between the start time expr and the end
time expr2. expr and expr2 are time or date-and-time expressions, but
both must be of the same type.

mysql> SELECT TIMEDIFF('2000: 01:01 00:00:00',
-> '2000:01:01 00:00:00.000001 ');
-> '-00:00:00.000001 '
mysql> SELECT TIMEDIFF('1997-12-31 23:59:59.000001 ',
-> '1997-12-30 01:01:01.000002 ');
-> '46:58:57.99999 9'

TIMEDIFF() was added in MySQL 4.1.1.
Michael Austin.
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2459
by: |-|erc | last post by:
<?php // Get the names and values for vars sent by index.lib.php3 if (isset($HTTP_GET_VARS)) { while(list($name,$value) = each($HTTP_GET_VARS)) { $$name = $value; }; };
4
2280
by: Gerry | last post by:
As I'm not a PHP-prgrammer at all, I just need Help with this: I have had a guestbook-page in Europe and will now have to move it to a US based-server. This makes the time-function showing time 6 hours wrong. The time should be GMT minus 6 hours. Can anyone help me with that? Her's the code: <?php header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache");
7
1718
by: Paul Charlton-Thomson | last post by:
Hi! I have nearly cracked this and am stuck on the last bit. I am asking my visitors to rank 8 different items (a,b,c,d,e,f,g,h) from 1 to 10 and then I want to draw a pie chart of those values. My page (draw_pie.php) that draws the pie chart works as it should and I link to it like this ... <A HREF="draw_pie.php?a='.$a.'&b='.$b.'&c='.$c.'&d='.$d.'&e='.$e.'&f='.$f.'&g=' ..$g.'&h='.$h.'">Pie Chart</A>
2
1851
by: DC Gringo | last post by:
I have an image control (that pulls an image off an ESRI map server): <ASP:IMAGE ID="imgZonedCountry" RUNAT="server"></ASP:IMAGE> In the code behind I am setting the ImageURL to a String value with url parameters like this: imgZonedCountry.ImageUrl = "http://server/servlet/com.esri.wms.Esrimap?param1=x&param2=y When it serves up the page, I'm getting "&amp;" in place of the "&"
4
3029
by: Luklrc | last post by:
Hi, I'm having to create a querysting with javascript. My problem is that javscript turns the "&" characher into "&amp;" when it gets used as a querystring in the url EG: /mypage.asp?value1=1&amp;value2=4&amp; ... which of course means nothing to asp.
4
2581
by: yaffa | last post by:
dear folks, i'm trying to append a semicolon to my addr string and am using the syntax below. for some reason the added on of the ; doesn't work. when i print it out later on it only shows the original value of addr. addr = incident.findNextSibling('td') addr.append('%s;') thanks
10
12885
by: | last post by:
In .NetCF, upon trying to access the following URL: http://rss.news.yahoo.com/rss/business via the following code: WebRequest webReq = WebRequest.Create(url); WebResponse webResp = webReq.GetResponse(); StreamReader sr = new StreamReader(webResp.GetResponseStream(), Encoding.GetEncoding("utf-8")); char buffer = new char;
11
6445
by: Jeremy | last post by:
How can one stop a browser from converting &amp; to & ? We have a textarea in our system wehre a user can type in some html code and have it saved to the database. When the data is retireved and
14
5935
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only because of this, so I hope some of you gurus can enlighten me with this :) In what circumstances can the "&amp;" in the source code be involuntary changed to "&" by a browser when or other software, when editing and uploading the file to the web...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.