JSHINER Posted May 15, 2008 Share Posted May 15, 2008 function getTodayCheck($db, $id_user = false) { $today = date('y-m-d'); return $db->getArray("SELECT * FROM quizzes_taken WHERE id_user = '$id_user' AND date_quiz = '$today'"); } $page['todayCheck'] = getTodayCheck($db, $_SESSION['id_user']); if($page['todayCheck']) { echo 'You took a quiz today!'; } The date_quiz is stored as 2008-05-15 11:17:48 But the $today is 2008-05-15 - how can I get them to interact nicely. Do I have to change the way it's stored in the database? Link to comment https://forums.phpfreaks.com/topic/105782-solved-date-question/ Share on other sites More sharing options...
BlueSkyIS Posted May 15, 2008 Share Posted May 15, 2008 if you don't need the time, it would be simpler to store the date as a DATE instead of DATETIME. if you don't want to change data types, you could simply append 00:00:01 or something on the end of $today before you store it. Link to comment https://forums.phpfreaks.com/topic/105782-solved-date-question/#findComment-542115 Share on other sites More sharing options...
JSHINER Posted May 15, 2008 Author Share Posted May 15, 2008 $today isn't being stored it's being compared to the stored date_quiz to see if they have taken a quiz today. Link to comment https://forums.phpfreaks.com/topic/105782-solved-date-question/#findComment-542123 Share on other sites More sharing options...
BlueSkyIS Posted May 15, 2008 Share Posted May 15, 2008 ok. if you don't want to change the field type, you could explode(" ",$dbdate) the value stored in the database and use the first part, which will be just the date: $ddate = $dateinthedatabase; $ddate_parts = explode(" ",$ddate); $date_without_time = $ddate_parts[0]; Link to comment https://forums.phpfreaks.com/topic/105782-solved-date-question/#findComment-542127 Share on other sites More sharing options...
PFMaBiSmAd Posted May 15, 2008 Share Posted May 15, 2008 To just use or return the DATE portion of a DATETIME, use the msyql DATE() function in your query - DATE(expr) Extracts the date part of the date or datetime expression expr. mysql> SELECT DATE('2003-12-31 01:02:03'); -> '2003-12-31' Link to comment https://forums.phpfreaks.com/topic/105782-solved-date-question/#findComment-542138 Share on other sites More sharing options...
JSHINER Posted May 15, 2008 Author Share Posted May 15, 2008 What I need to do is compare the "2008-05-15" part of each to determine if they're the same. Link to comment https://forums.phpfreaks.com/topic/105782-solved-date-question/#findComment-542153 Share on other sites More sharing options...
PFMaBiSmAd Posted May 15, 2008 Share Posted May 15, 2008 Mysql also has a current date function - CURDATE(), so your function can be simply written as - function getTodayCheck($db, $id_user = false) { return $db->getArray("SELECT * FROM quizzes_taken WHERE id_user = '$id_user' AND DATE(date_quiz) = CURDATE()"); } Link to comment https://forums.phpfreaks.com/topic/105782-solved-date-question/#findComment-542158 Share on other sites More sharing options...
The Little Guy Posted May 15, 2008 Share Posted May 15, 2008 How many records do you have in your database? If you don't have many, I would recommend changing them to a UNIX TIME STAMP Link to comment https://forums.phpfreaks.com/topic/105782-solved-date-question/#findComment-542159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.