Jump to content

Need help with time


topflight

Recommended Posts

Hello I have a table called called flights where it has all my flights info. But in that table I have a column called time. I want to put pull a random 15 flights who time is 30mins from the current time. For instance if the current time is 4:30 I want to pull a random 15 rows who time is 35 mins from now(Which is 4:30) how can I do that.

 

Thanks in advanced!

 

P.S please note that time in the database is in 24hour format and does not have ":" in it.

Link to comment
Share on other sites

Hello I have a table called called flights where it has all my flights info. But in that table I have a column called time. I want to put pull a random 15 flights who time is 30mins from the current time. For instance if the current time is 4:30 I want to pull a random 15 rows who time is 35 mins from now(Which is 4:30) how can I do that.

 

Thanks in advanced!

 

P.S please note that time in the database is in 24hour format and does not have ":" in it.

 

First, how do you store the time record in database?

- using mktime (e.g: 1267117200)

- 24 hours format (e.g: 10:01 or 19:04), or

- 12 hours format (e.g: 04:12 am or 02:00 pm)

Link to comment
Share on other sites

then u need to fetch the present time and add 30 to the last two digits if the count >=60 then add the subtract the last two digits value from 60 and add that + add 1 to the first two digits and now add the remaining to the obtained value. i guess u got the idea..i will work on the code and paste it here

Link to comment
Share on other sites

try this one..

u will get to know..

<?php
$time=date('Hi');

$time_add=$time+30;

$time_min=substr($time_add, -2);

$time_hr=substr($time_add, 0, 2);

if($time_min>=60)
{
    $sub_min_add=60-date('i');
   
    $sub_hr_add=date('H')+1;
   
    echo "Present  time is ".$time."<br>";
    echo "Time after 30 minutes is ".$sub_hr_add.$sub_min_add;
}
else
{
    echo "Present  time is ".$time."<br>";
    echo "Time after 30 minutes is ".$time_add;
}
?>

Link to comment
Share on other sites

<?php
include'config.php';


$get = mysql_query("SELECT * from `dep` WHERE dtime between date_format(now(),'%H%i') and addtime(date_format(now(),'%H%i'),30) order by rand() limit 15");

?>
<table width="100%">
<?
while($row = mysql_fetch_assoc($get)){?>
<td><? echo "$row[dtime]";?></td>



<?php
}
?>
</table>

 

I am not getting noting back with this.

 

P.S please note in the database the time is in 24hour format and does not a ":" between the number they look like this 1730 not 17:30

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.