Jump to content

[SOLVED] Date Question


JSHINER

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.