PHP - Days Until Timestamp?
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. Similar TutorialsHow 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 have this code :- $datestarted = $row['datestarted']; $datestart=date("l d/m/Y @ H:i:s",strtotime($datestarted)); Which is been echo'd like this :- echo ' <tr align="center"'.$rowbackground.'> <td>'.$datestart.'</td> <td align="center"> '; So for example I get this output :-Sunday 18/04/2021 @ 10:45:26 The data in the DB for the above is stored like this :-2021-04-18 10:45:26
What I'd like to do is also echo how many days ago this date was, all of the examples I've tried don't seem to work though? Hello I have a timestamp formated as : "2011-10-20 12:37:21" I need to show days left till this date (disregard the hours, minutes, seconds..), so I'll end up with 'there is "X" days left untill' I really cannot figure you all this date/time stuff, but hopefully this is not to difficult Anyone got a "quick" code for this? 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 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 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=320501.0 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! 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. 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. 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... 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"; 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. 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>"; 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? 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); Hey there, Thanks for taking the time to read my thread. I've encountered a problem that I cannot figure out a way to solve. I need to calculate the remaining days until a specified unix timestamp. I haven't yet figured out how to get the amount of days until the timestamp. If anybody could tell me how to get the remaining days until a unix timestamp I would be grateful, thanks. $epocTime = $math.newInt($math.divide("$today.getTime()", "1000"))) |