PHP - Strtotime To Check If They Voted Within The Last Hour
My site allows users to vote once per hour, and it checks the next time they vote if it's been 3600 seconds (1 hour) since their last vote. But, it always returns the value 0.
$grab = mysql_fetch_assoc($has_voted); $calc = strtotime($grab['date']) - strtotime(date("M-d-Y")); if($calc > 3600) { mysql_query("DELETE FROM votes WHERE ip = '". $_SERVER['REMOTE_ADDR'] ."'"); header("location:votes.php?id=". $id .""); } else { echo echo "You've voted within the last hour. Please wait ". $calc ." seconds."; } Similar TutorialsSo I am trying to check if the current time is one hour before a variable time: Code: [Select] $date_game=$dt->format('Y n j'.$pieces[2]); echo $date_game; echo date('Y n j H'); if (date('Y n j H') < $date_game) { echo "The time is before the stored time"; } This displays 2012 1 21 17:30 2012 1 21 16 i.e $pieces[2] = 17:30. and $dt formatted Y n j = 2012 1 21. The current Y n j H is 2012 1 21 16. I want to know if it is more than one hour until the date/time stored in $date_game. At the moment it just tells me that it is before that time. Can I do something like Code: [Select] $data_game - 1->format('H'); or something? Thanks guys $time="19:00:00"; how to do i output one hour later from the variable above? I am trying to display date and time below code display date correctly but when it come to display time it display 3 hour behind. eg. when it is 12:47 PM in my system it display 9:47 PM Code: [Select] <?php $todaydate=date("j - F - Y g:i:s a"); echo $todaydate; ?> Hi, i'm trying to create some detailed statistics about customer activity, i have entries in my mysql db when the customer has been active for the last time and want to create some statistics about that, basically a "online last 24 hours" but from specific countries. Now i've tried this: Code: [Select] $time = date('Y-m-d H:i:s'); $time24 = date("Y-m-d H:i:s", time()-((60*60)*24)); $query = "SELECT COUNT(*) as Anzahl FROM customers WHERE country = 'de' AND time BETWEEN '$time' AND '$time24' "; to get the current date and select all customers that have been available from the current date minus 24 hours, what's my mistake here, as this doesn't seem to work! Thanks Hi,
I have a blog which records the amount of views on each article. I now want to be able to work out the average number of views per hour.
How can I work out the number of hours passed from a datetime format?
From there I can just do views divided by hours passed.
Thanks in advance!
Hi I want to make something like this - My Sites index.php will be avail avail to user after he has clicked in a link that will come after every 24 Hour in my site. Means when a user first enters the site it will come and clicking in there the site will be avail avail. again after 24 Hour it will come again. But i am not getting how to do it. So need help SaKIB Hello, I have a very simple table... DAY (Y-m-d) / TIME (00:00:00) / POWER (INT) I am using a Jquery datepicker to select the date on the page, and that POST to the PHP file. I am trying to select values from Mysql to make 3 HighCharts Graphs using the selected day of the datepicker. I have started with the DAY graph PHP to get the values for each hour of a 24 hour day. I need to get the values for each hour... 23,12,15,35 etc... , and then I need for the 31 days of a month for the month graph, and 12 months of the year for the month graph all in the same way so the HighCharts can use the values to make the chart (3 php files, one for each graph) Here is the PHP I have for the 1 day that should get the 24 individual hour data, but it does not seem to work... <?php $choice = (isset($_POST['choice'])) ? date("Y-m-d",strtotime($_POST['choice'])) : date("Y-m-d"); $con = mysql_connect("localhost","root","mackie1604"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("inverters", $con); $sql = "SELECT HOUR(time), COUNT(power) FROM feed WHERE time = '".$choice."' GROUP BY HOUR(time) ORDER BY HOUR(time) "; $res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error()); $row = mysql_fetch_assoc($res); echo $row['choice'].'<br />'; ?> What have a written wrong in the sql query ??? Alan Hi all, I have a loop that is modifying a DateTime object. It goes through X number of times and adds 1 day to the date time object and stores the modified object in an array. I use ->add(new DateInterval('P1D')); For some reason it is losing an hour each time that I add a day. I start out at 19:00 and each iteration through the loop adds a day, but loses an hour. 2010-09-19 19:00:00 2010-09-20 18:00:00 2010-09-21 17:00:00 I can correct for this by doing ->add(new DateInterval('P1DT1H'));, but adding 25 hours instead of 24 hours doesn't make any sense to me. I am using PHP Version 5.3.1. Any ideas? Thanks, W Hello, I am trying to load an external image from a NOAA site directory. This image refreshes every three hours, starting with 0 and then 3,6,9,12.....21 in a 24 hour calendar, and are stored for days in advance. The date/time is in the file name. Originally I had written the script to refresh on the hour, and then realized the tri-hourly spacing. This is what I have: Code: [Select] <?php date_default_timezone_set('Etc/GMT-1'); $today = date("YmdH"); $pattern = '/WaveHeight_'.$today.'_mic.png'; $base_url = 'http://www.crh.noaa.gov/images/greatlakes/ndfd/MIC/dynamic2'; print '<a href="http://www.crh.noaa.gov/greatlakes/?c=map&l=lm&p=a"><img src="'.$base_url.$pattern.'" width= "237" hieght= "314" " ></a>'; ?> I am not fluent in php, but I assume I need a "If H=1,4,7,10,13,16,19,22; Then H+2 ; along with If H=2,5,8,11,14,17,20,23; Then H+1" to keep the images relatively current. I just can't quite wrap my head around how to express this. Any help is appreciated. Thank you. Hi guys, I have a PHP Script were user would enter a username and password to get access, but the problem I keep having is every half n hour or so user have to sign in again cause the keeps logging them out for some reason. Please I need your help and advice to make this stop. I'm trying to add 5 days to $today date: Code: [Select] <?php $exp_date = "2011-09-11"; $todays_date = date("Y-m-d"); $today = strtotime("+5 days", $todays_date); $expiration_date = strtotime($exp_date); if ($expiration_date > $today) { echo "Valid: Yes"; } else { echo "Valid: No"; } ?> Is +5 days used wrong? So, my problem is that I need to edit my Xmas calculator to understand when this year's Xmas is over, it will automatically jump to the next one (2011-12-25). I have no idea how to do this (noob to php...) Thanks in advance. Here's my code: Code: [Select] <?php $time=time(); $xmas=strtotime("2010-12-25 00:00:00"); $diff = $xmas - $time; $days=intval($diff/86400); $left=$diff%86400; $hs=intval($left/3600); $left=$left%3600; $mins=intval($left/60); $secs=$left%60; echo "<font size=12 face=corbel> Xmas is after:<br> <strong>$days days</strong><br> <strong>$hs hours</strong><br> <strong>$mins mins $secs secs</strong>! </font>"; ?> First time posting code and very new to php aka learning as I go... The below code works as shown, but in the 'else' clause, I'd like to replace the +4 with a variable. How to do this? I've tried, Code: [Select] $renewaldate = strtotime($subscriptiondate); $sft = "' +" . $duesmultiplier . " year'"; $next_year = date('Y-m-d',strtotime($sft,$renewaldate)); but this doesn't return what I expect. Perhaps this can't be done using this technique? Code: [Select] if($n == 0) { $renewaldate = strtotime($subscriptiondate); $next_year = date('Y-m-d',strtotime('next year',$renewaldate)); echo $next_year; } else { $renewaldate = strtotime($subscriptiondate); $next_year = date('Y-m-d',strtotime('+4 year',$renewaldate)); echo $next_year; } Thank you Hello! A user is going to input a date in the form "mm/dd/yyyy". I'd like to convert this to a time stamp so that I can store it via MySql. I've heard about the "strtotime" function in PHP but I'm not sure how it can tell that the user 03/04/2011 represents March,4th 2011 and not, say April,3rd 2011 (European version). Help with the correct syntax for conversion would be greatly appreciated. Thank you, Eric Hello,
I'm trying to use strtotime to add time to a mysql type timestamp. Any help would be appreciated. I think I have tunnel vision from looking at it when I know it has to be something obvious...lol
$start = "2014-05-22 09:16:24"; $type = 30; $endtime = date($start,strtotime("+ '.$type.' minutes")); echo "End: ".$endtime."</br>Start: ".$start;Right now it returns: End: 2014-05-22 09:16:24 Start: 2014-05-22 09:16:24 Hi, I have a bit of an issue with my application, I didn't notice until today, Sunday... Apparently PHP sees Sunday as the first day of the week, which I cannot fathom where it got hat notion from... but anyway, so I have the following samples of my code: Code: [Select] $mondayoflastweek = date('Y-m-d H:i:s', strtotime('monday last week')); $sundayoflastweek = date('Y-m-d 23:59:59', strtotime('sunday last week')); The crazy and very troublesome thing about the results of that code is that if you run that today, Sunday, it shows today as last week... So therefore, the next bit of code is just as problematic: Code: [Select] $mondayofthisweek = date('Y-m-d H:i:s', strtotime('monday this week')); $sundayofthisweek = date('Y-m-d 23:59:59', strtotime('sunday this week')); As you can imagine, for payroll, this is causing a big problem... My week starts at precisely 12:00 am on Monday and ends at precisely 11:59 pm on Sunday... Could someone please help me out with this... when i use strtotime('+3 HOURS') everything is fine. so why cant i use strtotime('+3.5 HOURS')? what would be the proper way to do this? I insert a time value using the following code
$ti= ( !empty($_POST['time']) ) ? "'{$_POST['time']}'" : 'NULL';
I want to insert a second time value into a differen column which would be the same time minus 1 hour
something along the lines of :
$ti2= ( !empty($_POST['time']) ) ? "'{$_POST['time'] -1 hour}'" : 'NULL';
What would be the correct way to do it
This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=332844.0 Hi, I am creating a date string using the following: $curDate = date("Y-m-d H:i:s"); However, what I want to do is take one hour off this so that $curDate now becomes the current date and time minus one hour. Thanks for your help. |