PHP - Data From 4 Days Ago
Hello,
I am trying to put together a mysql query that will return the number of visitors for four days ago, what i am trying to do is plot the last seven days visitors on a graph in the format of day seven, day six, etc and need to find away to get a count for each of those days. At the moment i am thinking about running various queries with each returning the results for a specific day. The code below is supposed to get the count of visitors four days ago. Not between now and four days ago but just for the 24 hour period which covers day 4. The current code just returns a value of 0. Any help would be appreciated. Code: [Select] $result = mysql_query("SELECT ip FROM ip_stats WHERE date= date_sub(NOW(), interval 4 DAY)"); $num_rows = mysql_num_rows($result); echo "$num_rows"; Similar TutorialsNot sure if I wrote this correctly but if anyone can just scan through this and let me know if it's fine. Thanks Code: [Select] <?php $db_link=mysql_connect ("localhost", "", "") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("commercial"); $sql = "DELETE FROM `comm` WHERE `date_created` < DATE_SUB(NOW(),INTERVAL 14 DAY)"; $result2 = mysql_query($sql, $db_link); ?> I need to display the last 30 days entries from database in PHP and here is the code that i am currently using, but its not working. While entering the data in database, the date format that i am using is this... Code: [Select] $subon = date("F j, Y, g:i a"); And to display the code i am using this query... Code: [Select] $start_date = date("F j, Y, g:i a", strtotime('-30 days')); $curr_date = date("F j, Y, g:i a"); $sql = "SELECT * FROM table WHERE status = 'approved' AND subon BETWEEN '$start_date' AND '$curr_date' ORDER BY ID DESC LIMIT 0, 5"; And then i am using the usual stuff to display the data but its not working. Somebody please help me... Thanks in advance. Please check the img link and you will understand Code: [Select] for ($index = 1; $index <= $numdays; $index++) { $users="SELECT invoice_date, DAY(invoice_date) as invoiceday, sum(total_amount) as fullamount from invoices WHERE MONTH(invoice_date)='".$month."' AND YEAR(invoice_date)='".$year."' GROUP BY invoiceday"; $res=mysql_query($users); $row=mysql_num_rows($res); while($fetch=mysql_fetch_array($res)){ echo "<tr id='". ( ( $j %2 == 0 ) ? 'row3' : 'row4' ) . "'>"; $explodedate=explode("-",$fetch['invoice_date']); $days=$explodedate[2]; $month1=$explodedate[1]; $year1=$explodedate[0]; $dates=date("jS", strtotime($fetch['invoice_date'])); echo "<td style='text-align:left;padding-left:12px'>".$index."</td>"; if($index==$dates){ echo "<td style='text-align:right;padding-right:12px'>".$fetch['fullamount']."</td>"; }else{ echo "<td style='text-align:right;padding-right:12px'>--</td>"; } echo "</tr>"; } } $total="SELECT SUM(total_amount) as fulltotal from invoices where MONTH(invoice_date)='".$month1."' AND YEAR(invoice_date)='".$year1."';"; $totres=mysql_query($total); $totfetch=mysql_fetch_assoc($totres); if($totfetch['fulltotal']==""){ echo "<tr><td>NOTHING FOUND</td></tr>"; }else{ ECHO "<TR>"; echo "<td style='color:#BD0000;padding-left:12px;border:1px solid #ccc;width:20%;height:40px;text-align:left'>TOTAL AMOUNT FOR ".$displaydate."</td>"; echo "<td style='color:#BD0000;border:1px solid #ccc;width:20%;height:40px;text-align:right;padding-right:12px'>".$totfetch['fulltotal']."</TD></TR>"; } echo "</table>"; I'm trying to figure out if today's current date and time falls between Mon & Fri, but so far, I can't get it to work. Can anybody look at my code and see what I'm doing wrong? Code: [Select] <?php $day_start = date('D h:i a', strtotime("Mon 05:30")); $day_end = date('D h:i a', strtotime("Fri 10:00")); $day_current = date('D h:i a', strtotime("+1 hours")); if (($day_current > $day_start) && ($day_current < $day_end)) { echo "yup"; } else { echo "nope"; } ?> Thanks in advance Hi I am trying to add a field to a database that is 4 days from the date the record is added, but it is not adding a value Code: [Select] $end_date=strtotime("+ 4 days"); $add_vehicle_sql=mysql_query("INSERT INTO `tbl_auction_lot`(`cust_id`,`reserve`,`make`,`model`,`spec`,`fuel`,`doors`,`mot_date`,`fns`,`fos`,`rns`,`ros`,`condition`,`reg_no`,`service_history`,`sale_type`,`status`,`keepers`,`gearbox`,`emissions`,`colour`,`date_first_reg`,`date_manufacture`,`bhp`,`engine_size`,`end_date`) VALUES ('$seller_id','$reserve','$make','$model','$body_style','$fuel_type','$no_of_doors','$mot','$fns','$fos','$rns','$ros','$vehicle_condition','$vrm','$service_history','auction','$status','$prev_keepers','$gearbox','$emissions','$colour','$date_reg','$date_man','$bhp','$engine_size','$end_date')") or die(mysql_error()); What am I doing wrong and what is there a better way to achieve the desired result. When I try to add 30 days: Code: [Select] $date = date("Y-m-d"); $date = strtotime(date("Y-m-d", strtotime($date)) . " +30 days"); echo $date; and I echo date I get 1330664400 How do I get it to echo out 3/1/2012? I know the answer lies in the strtotime but I can't figure it out. I know it's a simple problem for most of you... Hi, I have db table that records the days (Sunday, Monday...) when the employee login to the system. Say that the employee logged in on Monday then Logged in on Wednesday so this means he was absent on Tuesday. I calculated the number of days to get the answer 2 (between Wednesday and Monday before logging in on Wednesday) how to get the name of the missing day "Tuesday"? code: $curdate = date("Y-m-d"); $currday = date('l'); $lastdate = $row['indate']; $lastdayin = $row['lastdayin']; if ($lastdate !=Null) { $misseddates = strtotime($curdate) - strtotime($lastdate); $misseddates = $misseddates / 86400; echo $misseddates; $misseddays = strtotime($lastdayin) - strtotime($currday); $misseddays = $misseddays / 86400; echo $misseddays; } I tried to get the name of day in the last step but it only calculates 5 in numbers how to get the name. I want the answer to be "Tuesday" as of the example. Thanks. Hello. I want to generate the initial of the day of all the days of a chosen month. Meaning, if I choose this month it will give me: TFSSMTWTFSSMTWTFSSMTWTFSSMTWTF Is that clear? Can anybody help me? thanks! This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=320501.0 Hi there, for every case we have "gooo" as commen in all how this could be one code using anything like elseif or switch whatever... if($refere && (stripos($r, $refere) === false)){ echo "x1" }else{ echo"goooo" } And if($limited && ($line[hits] >= $limited)){ echo "x2" }else{ echo"goooo" } And if($pword && (isset($_POST['password']) && $_POST['password'] == $pword) ){ echo"goooo" }else{ echo"x3" } And if ($line[capt] == 1 && ($_SESSION["security_code"]) ){ echo"goooo" }else{ echo"x4" } thanks in advance I have a SQL row that has a date field: ex: 2010-11-01. When a car is sold there either is a 30 day warranty, a 60 day warranty, or 0 day warranty. What I'm trying to do is display when the vehicles warranty expires, based on the date it was sold, or when did it expire based on the same sold date pulled from the database. Example using last months date: 2010-10-01 60 day: "Expires 11-30-10" 30 day: "Expired 11-01-10" I can not seem to use the date function properly... Any help would be greatly appreciated. Hey there, Thanks for taking the time to read my thread. My issue is if I'm given a time stamp in PHP how could I calculate the number of days until that time stamp?. Thanks for your time. How can I check in php if a timestamp was x days ago For example the timestamp 1287677304 , how can I check if it was more than 2 days ago? Thanks lots Jake Hi, I need to calculate absent percentage but not sure how. working days from Sunday to Thursday every week so 5 working days a week. i will calculate the absent days from joining date until current date. Example if joining date is 24-3-2020 and today's date is 7-4-2020 i should get the number of absent days to 11 days since both Friday and Saturday are excluded. How to do that? here is what I have: $workingdays = $curdate - $joindate; $workingdays = $workingdays - $absent = ($counter / $workingdays) * 100; the second line i missing the number of days for (Fridays and Saturdays) that should be excluded from calculations. The third line i did calculate the actual working days ($counter) for the employee so then i can get percentage of absent days. How to exclude the weekend days from calculations? Edited April 1, 2020 by ramiwahdanmistake in dates Hello all, The exact thing that i need is to calculate how much days there is in between two dates. The only problem is that every thing that i found dont care about leap year Anyone have a function to do that? Hi guys, I've hit a brick wall here and am in need of your help. I'm pretty new to PHP and have limited knowledge to say the least. I'll explain what it is I'm trying to do. Set start date as 01/01/2004 (dmY) $oFour Set how many days has it been since then? $today Set how many days it was from $ofour 30 days ago. $today -30 = $thirtyDaysAgo But the problem is I don't know how to make date('z'); work from 2004 and not 01/01/2010. So $today will be how many days it has been since the start of 2004 and $thirtyDaysAgo will be $today -30. I can set up $thirtyDaysAgo no problem but it's just finding out how to get the $today number... Hope anyone can offer a little light to my situation :/ Mav I have this block of code that was written by someone years ago :-
<?php class BoDelivery { public function EstimatedDays($off, $standard_days, $saturday, $delay) { $today = date("N"); // Weekday - number 1-7 $now = strtotime("now"); // Unix $off_array = explode(":", str_replace(".", ":", $off)); $off_unix = mktime($off_array[0], $off_array[1], "00", date("n"), date("j"), date("Y")); $sending_days_from_now = 0; if ($now > $off_unix) { $sending_days_from_now++; } $sending_day = $today + $sending_days_from_now; switch ($sending_day) { case 6: $sending_days_from_now++; $sending_days_from_now++; break; case 7: $sending_days_from_now++; break; } $sending_day = $today + $sending_days_from_now; // Estimated delivery time $delivery_days = $standard_days; $over_weekends = 0; // Add Delay if ($delay) { $delivery_days = $delivery_days + $delay; } if ($sending_day == 5 && !$saturday) { $delivery_days++; $delivery_days++; $over_weekends++; } $delivery_day = $sending_day + $delivery_days; switch ($delivery_day) { case 6: if (!$saturday) { $delivery_days++; $delivery_days++; $over_weekends++; } break; case 7: $delivery_days++; $over_weekends++; break; } if ($over_weekends == 0 && $delivery_days > 5) { $delivery_days++; $delivery_days++; } $delivery_day = $sending_day + $delivery_days; switch ($delivery_day) { case 13: $delivery_days++; $delivery_days++; $over_weekends++; break; case 14: $delivery_days++; $over_weekends++; break; } $delivery_day = $sending_day + $delivery_days; $delivery_days = $delivery_day - $today; return $delivery_days; } } ?>
Which is supposed to calculate the number of days for delivery, taking into account weekends & with a delay variable that we can set. It isn't working as expected, may never have worked(??) or maybe down to PHP upgrades. For example, if today (18th)I set the delay to 2 days the delivery estimate is the 21st (which is correct), if I change the delay to 3 OR 4 it becomes the 24th, 5 then becomes the 26th! I can't get my head around the code at all, I wonder if someone could assist in what may be going on or add comments to the code snippets so I can maybe work it out?
Thanks for any help. Hi fellas, this is really kicking my arse and i know its so simple! I retrieve a date from the database, done! I am manipulating it to display as i want, done! How the hell do i add 365 days to this date? $date= ($row['date']); $subscription = strtotime($date); echo "<p>Subscription renewal date: ". date('l jS F Y', $subscription) . "</p>"; please could some one help me i need to limit the query by timestamp for the last 7 days here is my code on the php side Code: [Select] <?php $db = @mysql_connect("localhost", "8conv", "*****") or die("Connection Error: " . mysql_error()); mysql_select_db("tempmonitor") or die("Error connecting to db."); $sql = "SELECT *, UNIX_TIMESTAMP(datetime) AS datetime FROM 8conv"; $result = mysql_query($sql); $data = array(); while ($row = mysql_fetch_array($result)) { $temp1[] = array($row['datetime'] * 1000, (int)$row['temp1']);; } $temp1 = json_encode($temp1); is there an easy way to add weekdays to a stored date ... so far i have echo date ( 'Y-m-j' , strtotime ( '5 weekdays' ) ); this adds 5 weekdays to the current date , can i have it add 5 weekdays to say $TableDate 1; Thanks in advance... |