PDA

View Full Version : PHP Date() returning default value


tinuz
05-15-2017, 05:40 AM
Hey guys. I'm currently working on a new mod for vBulletin 4.x

In short it's a new panel that allows teammembers to monitor for new posts on the forum through Ajax, like the mod over here: https://vborg.vbsupport.ru/showthread.php?t=125947, but instead of working like a RSS feed, it only shows posts that haven't been checked by a teammember. Once a teammember opened the post or new thread, it disappears from the list.

Anyway, right now I'm working on a small part that keeps track of how many posts were checked by each teammember every single day. For that I'm editing the file:

includes/functions_bigthree.php

After the query inside the if-statement on line 168:

if ($vbulletin->options['threadmarking'] AND $userid)

I've written the following:

/* Custom post read count mod */
$modP_teamIDs = array(1,2,3,4,5,6,7,8,9);
$modP_today = date("Y-m-d");

if(array_search($userid, $modP_teamIDs) !== false){
$modP_getToday = $db->query_read("
SELECT posts
FROM " .TABLE_PREFIX ."postsreadcount
WHERE userid = $userid
AND mydate = $modP_today
");

$modP_getToday_count = $db->num_rows($modP_getToday);

if($modP_getToday_count > 0){
while($modP_getToday_fetch = $db->fetch_array($modP_getToday)){
$modP_posts = $modP_getToday_fetch['posts'];
}
$modP_posts++;

$db->query_write("
UPDATE " . TABLE_PREFIX . "postsreadcount
SET posts = $modP_posts
WHERE userid = $userid
AND mydate = $modP_today
");
} else {
$modP_posts = 1;

$db->query_write("
INSERT INTO " . TABLE_PREFIX . "postsreadcount
(userid, mydate, posts)
VALUES
($userid, $modP_today, $modP_posts)
");
}
}
/* End custom post count mod */

The code is working perfectly fine, but

$modP_today = date("Y-m-d");

is returning me 0000-00-00 instead of the current date as I would expect. I know I could use the constant TIMENOW defined in vBulletin, but that one returns a UNIX timestamp, instead of a normal date.

So could anyone tell me why this is happening? Could be a local scope problem?

--------------- Added 1494835639 at 1494835639 ---------------

I've fixed the issue by using CURDATE() inside my queries instead of relying on PHP to do it. Still, if anyone could tell me why it didn't work, that would be perfect :)

--------------- Added 1494855999 at 1494855999 ---------------

It turns out the variable was returning the correct date as expected. I should've wrapped the variable inside quotes in the queries: AND mydate = '$modP_today'