shamsuljewel Posted September 13, 2007 Share Posted September 13, 2007 Hello, I have a table name quiz1 there I have some fields I use a field name time int(11) where I save the time of the users quiz participation. I use time() function to insert it. now I want to execute a query... I need the members who are attent quiz in (current date and before time 9am) or (previous date after 9am). so hows the query???any help...preferable. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/69176-solved-time-and-date-query-plessssssshelp/ Share on other sites More sharing options...
Barand Posted September 13, 2007 Share Posted September 13, 2007 try <?php $time2 = mktime(9,0,0); $time1 = strtotime('-24 hours', $time2); $sql = "SELECT some, fields FROM mytable WHERE `time` BETWEEN $time1 AND $time2"; Quote Link to comment https://forums.phpfreaks.com/topic/69176-solved-time-and-date-query-plessssssshelp/#findComment-347880 Share on other sites More sharing options...
fenway Posted September 15, 2007 Share Posted September 15, 2007 try <?php $time2 = mktime(9,0,0); $time1 = strtotime('-24 hours', $time2); $sql = "SELECT some, fields FROM mytable WHERE `time` BETWEEN $time1 AND $time2"; MySQL has a STR_TO_DATE() function too... Quote Link to comment https://forums.phpfreaks.com/topic/69176-solved-time-and-date-query-plessssssshelp/#findComment-348830 Share on other sites More sharing options...
Barand Posted September 15, 2007 Share Posted September 15, 2007 Thanks, how would I use it for this problem? Quote Link to comment https://forums.phpfreaks.com/topic/69176-solved-time-and-date-query-plessssssshelp/#findComment-348949 Share on other sites More sharing options...
fenway Posted September 15, 2007 Share Posted September 15, 2007 Actually, didn't realize it was based on the current time, so it's a bit different: SELECT some, fields FROM mytable WHERE `time` BETWEEN CURDATE()+INTERVAL 9 HOUR AND CURDATE()+INTERVAL 9 HOUR-INTERVAL 1 DAY Quote Link to comment https://forums.phpfreaks.com/topic/69176-solved-time-and-date-query-plessssssshelp/#findComment-349045 Share on other sites More sharing options...
shamsuljewel Posted September 16, 2007 Author Share Posted September 16, 2007 thanks all this is great...i do not know strtotime function before... I have solved my problem. Anyway thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/69176-solved-time-and-date-query-plessssssshelp/#findComment-349485 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.