Jump to content

Adding Time


Jamz

Recommended Posts

Hi again guys,

 

Right, I have two times being output from a database... The first time is the time something is booked in for (eg: 16:30:00) and the second time is the duration that thing is booked in for (eg an hour and a half - 01:30:00)

 

Now, I want to figure out when that thing will be finished, so using the two examples above, it will be finished at 18:00:00, I've tried a few things with no success :(

 

Please help

 

Cheers

Link to comment
Share on other sites

Hmm think thats another SQL function that I dont really need... This is the code I have so far, and I would like the added time to be output into $till_time. You can see in the code I already get an output, but I would like the full output and not just the hour

 

<?php
dbconnect(); // Include function for database connection
$result = mysql_query("SELECT * FROM booking WHERE date='$date' and store='$store' ORDER BY time") or die ('Could not select ' . mysql_error());	
echo '<table class="cal" width="500px"><tr><th>Bookings</th></tr><tr><td>';

if(mysql_num_rows($result)==0){
	echo "Nothing Booked In Today";
}else{
	echo '<table width="660px" border="1"><tr>
    		<th>Time</th><th>Name</th><th>Car</th>
    		<th>Description</th><th width="100%">Comments</th><th>Paid?</th>
    		<th>Contact</th><th>Misc</th></tr>';
	while($row = mysql_fetch_array($result)){
		$till_time = $row['time'] + $row['duration'];
	echo'
  			<tr>
    			<td>'.$row['time'].'<br>till<br>'.$till_time.'</td>
   			 	<td>'.$row['customer_name'].'</td>
    			<td>'.$row['car_make'].' '.$row['car_model'].'<br>'.$row['car_year'].'</td>
    			<td>'.$row['work_desc'].'</td>
    			<td>'.$row['comments'].'</td>
    			<td>'.$row['paid'].'</td>
    			<td>'.$row['contact'].'</td>
			<td>Edit<br>Cancel</td>
  			</tr>';
	}
	echo '</table>';

Link to comment
Share on other sites

Change your query as follows and this should get you an additional field returned in your db results called 'till_time'

 

$query = "SELECT *, DATE_ADD(start, INTERVAL TIME_TO_SEC(duration) SECOND) AS till_time
          FROM booking
          WHERE date='$date'
            AND store='$store'
          ORDER BY time";
$result = mysql_query($query) or die ('Could not select ' . mysql_error());

Link to comment
Share on other sites

Is there anyway to get it to output in an array:

 

ie:

 

<?php
dbconnect(); // Include function for database connection
$result = mysql_query("SELECT *, DATE_ADD(time, INTERVAL TIME_TO_SEC(duration) SECOND) AS till_time FROM booking WHERE date='$date' and store='$store' ORDER BY time") or die ('Could not select ' . mysql_error());	

while($row = mysql_fetch_array($result)){
echo'
  			<tr>
<td>'.$row['time'].'<br>till<br>'.$row['till_time'].'</td>
   			 	<td>'.$row['customer_name'].'</td>
    			<td>'.$row['car_make'].' '.$row['car_model'].'<br>'.$row['car_year'].'</td>
</tr>';
}

 

As what ive just added

<?php $row['till_time']; ?>

does not output anything :(

Link to comment
Share on other sites

DATE_ADD() expects a DATE or DATETIME for the first parameter and produced an error in my query browser - Incorrect datetime value: '16:30:00'.

 

Use this for that part of the query -

 

SEC_TO_TIME(TIME_TO_SEC(time) + TIME_TO_SEC(duration)) AS till_time

Link to comment
Share on other sites

DATE_ADD() expects a DATE or DATETIME for the first parameter and produced an error in my query browser - Incorrect datetime value: '16:30:00'.

 

Use this for that part of the query -

 

SEC_TO_TIME(TIME_TO_SEC(time) + TIME_TO_SEC(duration)) AS till_time

 

Perfect, works as it should :D

 

Cheers for that

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.