topflight Posted February 11, 2010 Share Posted February 11, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/191709-need-help-with-time/ Share on other sites More sharing options...
topflight Posted February 11, 2010 Author Share Posted February 11, 2010 Any help please? Quote Link to comment https://forums.phpfreaks.com/topic/191709-need-help-with-time/#findComment-1010480 Share on other sites More sharing options...
tengkie Posted February 11, 2010 Share Posted February 11, 2010 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) Quote Link to comment https://forums.phpfreaks.com/topic/191709-need-help-with-time/#findComment-1010488 Share on other sites More sharing options...
topflight Posted February 11, 2010 Author Share Posted February 11, 2010 24 hours here is an example of one of the time in the database 1750 Quote Link to comment https://forums.phpfreaks.com/topic/191709-need-help-with-time/#findComment-1010492 Share on other sites More sharing options...
topflight Posted February 11, 2010 Author Share Posted February 11, 2010 so... lol Quote Link to comment https://forums.phpfreaks.com/topic/191709-need-help-with-time/#findComment-1010496 Share on other sites More sharing options...
Deoctor Posted February 11, 2010 Share Posted February 11, 2010 i cannot understand ur example abt the 4:30 thing... Quote Link to comment https://forums.phpfreaks.com/topic/191709-need-help-with-time/#findComment-1010576 Share on other sites More sharing options...
topflight Posted February 11, 2010 Author Share Posted February 11, 2010 For instance if the current time is 4:30 I want to put a rand 6 rows who time is 30-40 mins later than the current time (which is 4:30) Quote Link to comment https://forums.phpfreaks.com/topic/191709-need-help-with-time/#findComment-1010727 Share on other sites More sharing options...
Deoctor Posted February 11, 2010 Share Posted February 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/191709-need-help-with-time/#findComment-1010731 Share on other sites More sharing options...
topflight Posted February 11, 2010 Author Share Posted February 11, 2010 I am confused may you please write an example query please. Quote Link to comment https://forums.phpfreaks.com/topic/191709-need-help-with-time/#findComment-1010733 Share on other sites More sharing options...
Deoctor Posted February 11, 2010 Share Posted February 11, 2010 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/191709-need-help-with-time/#findComment-1010738 Share on other sites More sharing options...
topflight Posted February 11, 2010 Author Share Posted February 11, 2010 ok, but I have a table called leaving time in the database and I want to pull all the rows who leaving time is 30 mins from the current time. That's what I am trying to do, how can I do that? Quote Link to comment https://forums.phpfreaks.com/topic/191709-need-help-with-time/#findComment-1010742 Share on other sites More sharing options...
taquitosensei Posted February 11, 2010 Share Posted February 11, 2010 select * from yourtable where timecolumn between date_format(now(),'%H%i') and addtime(date_format(now(),'%H%i'),30) order by rand() limit 15 gets you 15 random rows where the time is between now and 30 minutes from now. replace the appropriate values with your table and column name Quote Link to comment https://forums.phpfreaks.com/topic/191709-need-help-with-time/#findComment-1010784 Share on other sites More sharing options...
topflight Posted February 11, 2010 Author Share Posted February 11, 2010 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/191709-need-help-with-time/#findComment-1010814 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.