Jump to content

Recommended Posts

I need to get the count of how many people have signed my petition on the current day. I have this:

$time = date("d");
$getcount = "SELECT * FROM `signatures` WHERE `timestamp`='{$time}'";
$timequery = mysql_query($getcount) or die(mysql_error());
$signed_today = mysql_num_rows($timequery);

 

Which obviously will return 0 (zero). I need to get each timestamp and compare them for the day only. I have 600 and growing records so I don't want anything heavy. Can anyone help?

Link to comment
https://forums.phpfreaks.com/topic/159411-compare-timestamps-for-day/
Share on other sites

That is not what he wanted though. He wanted entries on a particular day, not entries within a 24 hour interval. If you want the entries for e.g. May 23rd, but the time is 11:00 AM, then -24 hours up until now would be May 22nd 11:00 AM to May 23rd 11:00 AM. This means you, incorrectly, will get entries from the yesterday as well.

 

What you can do is something like this:

 

$timestamp = time();
$start = mktime(0, 0, 0, date('n', $timestamp), date('j', $timestamp), date('Y', $timestamp));
$end = mktime(23, 59, 59, date('n', $timestamp), date('j', $timestamp), date('Y', $timestamp));

$getcount = "SELECT * FROM `signatures` WHERE `timestamp` BETWEEN {$start} AND {$END}";

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.