Jump to content

Recommended Posts

'um, what format is the date stamp in mysql?

 

if its standard:  YYY-MM-DD

 

then:

 

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

$sql = "SELECT * FROM table WHERE datestamp = $today";

Does mysql date stamp every entry?  I thought you had to put a date stamp field in the table before you sort off of it...
Link to comment
https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343137
Share on other sites

date is a timestamp 10 digits

 

I'm assuming this 10-digit date field is being populated with each new entry right?

 

then similar to my first suggestion:

$today = strtotime(date("Y-m-d")); //returns 10 digit time stamp of midnight this morning

$sql = "SELECT * FROM table WHERE date >= $today";

 

 

Link to comment
https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343141
Share on other sites

Example:

<?php 
$res = mysql_query("select * from blah") // a query that returns an empty set 
$row = mysql_fetch_array($res); // get's 0 since there's no return 
echo count($row); // echos 1 - since $row is not an array 
echo $row[0]; // echos "", but casts $row as an array? 
echo count($row); // echos 0 now 
?> 

Link to comment
https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343249
Share on other sites

I was wondering

 

How to count entries or hits made each hour of the day?

 

why didn't you ask that then?

 

to count the hits for today, use my previous code then just count the rows returned:

 

$today = strtotime(date("Y-m-d"));

$sql = mysql_query("SELECT * FROM table WHERE date >= $today");

echo mysql_num_rows($sql);

 

to get results by hour, modify the $today string in from my example.

look at http://www.php.net/date and http://www.php.net/strtotime

Link to comment
https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343273
Share on other sites

didn't test this but how 'bout:

 

<?php

$start= strtotime(date("Y-m-d"));
$sql = mysql_query("SELECT date FROM table WHERE date >= $start");

for($i=0;$i<mysql_num_rows($sql); $i++){
$date = mysql_result($sql,$i,0);
$nextHour = $start + (60*60); 

  if($date >= $start && $date < $nextHour){
   $hour[$i] = $hour[$i] + 1;
  }

$start= $nextHour;
}

print_r($hour); //array of hours with values equal to number of entries each hour

?>

Link to comment
https://forums.phpfreaks.com/topic/68254-select-todays-entries/#findComment-343411
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.