Jump to content

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

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

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

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.