PHP - Odd Date Calculation
Hi. I am writing software to choose employees for drug testing. Originally it was choosing 5 per day, Mon-Thu. No problem there, that's easy. Now, they want to ensure everyone gets tested each calendar year. So now I need the program to look at the date and calculate the days between now and 12/31 then divide the people that haven't been tested by days to get number per day that need testing so it gets all done by the end of the year.
The snag I hit is how to calculate it. I can easily get days to 12/31, but I need to drop the Fridays, Saturdays and Sundays of each week. That has me a little perplexed. Is there a way to make that kind of calculation? Thanks!
Similar Tutorials
Hi, Hi I don't understand what I'm doing wrong, I want to subtract 6 months from my date, but I get 1969/07 as an answer? Code: [Select] <?php $date = date('Y/m'); echo $date; echo "<br/>"; $date1 = date ("Y/m", strtotime("-6 month", strtotime($date))); echo $date1; ?> Hi guys, $T_Start_Date = "2011-10-23"; $P_Days = "30"; I tried this Its working: $T_End_Date = date('Y-m-d', strtotime("+$P_Days days"); but why am not getting this: $T_End_Date = date($T_Start_Date, strtotime("+$P_Days days")); thanks Hi i was wondering if its possible to not display negative values or maybe there some other way to do this when date is calculated. in this case i have days, and the result brings "- 123" or "- 56" i just want it to show anything that's not negative. thanks. Code: [Select] $start_ts = strtotime($row['Applied']); // when process started $end_ts = strtotime($row['Approval']); // when process finished $Approval = floor(($end_ts - $start_ts) / (60*60*24)); // days difference from start to finish ok, i had some great help from this forum recently so i hope for the same outcome this time probably a rather easy question for most of you, i have a form that visitors use to input date using php (submission_date) in to db. date is then entered in db as a VARCHAR (i.e. Mar-15-2011), what i would like is to have another field which would calculate time elapsed. Since calculation can be only done on date not varchar ( i assume), i would need to have submission date also as a DATE and then passed on to a new field for calculating total time. does that make sense? lol I would really appreciate any pointers or help with this, not sure if im going in the right direction, but thats a start thank you! hi, I have some code that deals with sending out reminders for appointments due the following day. So if today is the 21/3 then only reminders for appointments due on the 22/3 should be sent. Currently this isn't happening... If reminders are sent on 21/3 at 9.50 am, my code adds 24 hours to this datetime and sends reminders due for all appointments that fall bewteen 21/3 9.50am and 22/3 9.49 am. What I want to do is simply send all reminders for appointments that are on the 22/3 exclusive of time. I'm not sure how do this in php, which uses the unix datetime format to mildy complicate issues anhy help or solutions would be massive, thanks.how to Code: [Select] $days = time() + (1 * (60 * 60 * 24)); $apts = $db->fetch_all('status = 1 AND time > ? AND time < ?', array(time(), $days)); how to calculate the difference between the current datetime from the stored one(ie date_field = 2020-08-09 23:13:06) in order to compare with 15min, i mean if the resulted time exceed 15 min and not the same day(date) the provided link will show expire message. i.e $some_variable = $date_in_db - current_date; if((time() - $some_variable > 15*60) && not the same day or the same day){ echo 'the link has expired'; }
I was wondering if someone could help me out with calculating and displaing dates. Below i posted html of my page and also php for it. It has a field called "DATE1" thats where visitors input the date, after that it gets posted to db and i pull it and disply it in a grid on my site. I would also like to have a column that shows time elapsed between the "DATE1" and current date. I sorta figured how to calculate the dates using the php, but really stuck on how do i actually display it now. from what i been told so far i shouldn't create a new column for that, instead calculate and display the values on the fly, could some step me through this please, or get me started... thanks so much! my html Code: [Select] <form id="signupForm" method="POST" action="processform.php"> <div> <fieldset> <legend>Signup Form</legend> <label for="Country">*Country:</label> <select name="Country"> <option value="">-----</option> <option value="Canada">Canada</option> <option value="UK">UK</option> <option value="France">France</option></select></div></p> <p><label for="Nationality">*Nationality:</label> <div><select name="Nationality"> <option value="">-----</option> <option value="Afghanistan">Afghanistan</option> <option value="Albania">Albania</option> <option value="Algeria">Algeria</option></select></div></p> <p><label for="Province">*Province:</label> <div><select name="Province"> <option value="">-----</option> <option value="British Columbia">British Columbia</option> <option value="Alberta">Alberta</option> <option value="Saskatchewan">Saskatchewan</option></select></div></p> <p><label for="DATE1">*Date:</label> <div><select name="day" id="Date1" class="regularfont"><option value="" selected="selected"></option> <option value="1">01</option> <option value="2">02</option> <option value="3">03</option></select> <select name="month" id="Date2" class="regularfont"><option value="" selected="selected"></option> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option></select> <select name="year" id="Date3" class="regularfont"><option value="" selected="selected"></option> <option value="2014">2014</option> <option value="2013">2013</option> <option value="2012">2012</option></select> </fieldset> </div> <p> <div align="center"><input type="submit" name="submit" value="Submit your entry"></div> </p> </form> <p> Code: [Select] <?PHP $hostname = "localhost"; $db_user = ""; $db_password = ""; $database = ""; $db_table = ""; $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db($database,$db); //here i use this to calculate the date but really unsure how to further display the results Code: [Select] if (isset($_REQUEST['submit'])) { // Get current time, or input time like in $date2 $date1 = time(); // Get the timestamp of DATE1 $date2 = mktime(0,0,0,date($_POST['month']),date($_POST['day']),date($_POST['year'])); $dateDiff = $date1 - $date2; $TotalTime = floor($dateDiff/(60*60*24)); echo "$TotalTime"; } for posting to db Code: [Select] if(isSet($_POST['submit'])) { $country = mysql_real_escape_string($_POST['Country']); $nationality = mysql_real_escape_string($_POST['Nationality']); $province = mysql_real_escape_string($_POST['Province']); $date = $_POST['day'].'-'.$_POST['month'].'-'.$_POST['year']; $myQuery = "INSERT INTO {$db_table} (`Country`,`Nationality`,`Province`,`DATE1`) VALUES ('{$country}','{$nationality}','{$province}','{$date}')"); if(mysql_query($myQuery)) { echo 'Record inserted.'; } else { echo 'An error has occurred: '.mysql_error(); } } ?> Hi, I want to calculate the future month, i have used following code to calculate the date $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime('2010-01-31')) . " +3 month")); It gives me 2010-03-03 But i need to get 2010-02-28 OR just month is enough like 2010-02 Thank you Nikhil Hey, I'm using a script which allows you to click on a calendar to select the date to submit to the database. The date is submitted like this: 2014-02-08 Is there a really simple way to prevent rows showing if the date is in the past? Something like this: if($currentdate < 2014-02-08 || $currentdate == 2014-02-08) { } Thanks very much, Jack Hi, I have a calculation issue in my php. Below is my code: $ Code: [Select] moduletotal = 0; $modulecount = 0; $sessionweight = 0; while ($row = mysql_fetch_array($result)){ $moduletotal += $row['Mark']; $modulemark = (int)($moduletotal); // Here and above is the calculation which is simply adding the total number of marks // Below is the code that displays my results. The variable of the calculation is shown at the end of the last if statement (3rd one down) $output = ""; $studentId = false; $courseId = false; $moduleId = false; if($studentId != $row['StudentUsername']) { $studentId = $row['StudentUsername']; $output .= "<p><strong>Student:</strong> {$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})"; } if($courseId != $row['CourseId']) { $courseId = $row['CourseId']; $output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <br><strong>Year:</strong> {$row['Year']}</p>"; } if($moduleId != $row['ModuleId']) { $moduleId = $row['ModuleId']; $output .= "<p><br><strong>Module:</strong> {$row['ModuleId']} - {$row['ModuleName']} {$row['Credits']} $modulemark</p>"; } $output .= "<p><strong>Session:</strong> {$row['SessionId']} {$row['Mark']} {$row['Grade']} {$row['SessionWeight']}%</p>"; } echo $output; ?>The Results look like this at the moment (The answer the calculation is next to each Module): Student: Mayur Patel (u0867587) Course: INFO101 - Bsc Information Communication Technology Year: 3 Module: CHI2550 - Modern Database Applications 20 72 (72 is the answer to the calculation for the first module but this is incorrect at it should also add the 67 and thus become 139) Session: AAB 72 A 20% Session: AAE 67 B 40% Module: CHI2513 - Systems Strategy 20 200 (200 is the answer to the calculation for this module but this is incorrect it should be only 61. But what it has done is that it has added the 72 and 67 from the first module and added it with the 61 in this module) Session: AAD 61 B 50% SO WHAT MY QUESTION IS HOW CAN I GET THE CALCULATION SO THAT IT ONLY ADDS UP EACH SESSION MARKS THAT BELONGS TO A MODULE ONLY? IN THE EXAMPLE ABOVE IT SHOULD ONLY ADD THE MARKS FOR SESSION AAB AND AAE IN THE MODERN DATABASE APPLICATIONS MODULE AND THEN WHEN IT GETS TO THE NEXT MODULE WHICH IS SYSTEMS STRATEGY, THE MARKS FOR THAT MODULE SHOULD START AGAIN AND ADD ON THE MARKS FOR THE SESSION AAD IN THAT MODULE. HOPEFULLY YOU UNDERSTAND AND THANK YOU Below is the query if you want to look at it: Code: [Select] $query = " SELECT c.CourseName, st.CourseId, st.Year, st.StudentUsername, st.StudentForename, st.StudentSurname, s.ModuleId, s.SessionId, s.SessionWeight, gr.Mark, gr.Grade m.ModuleName, m.Credits, FROM Course c INNER JOIN Student st ON c.CourseId = st.CourseId JOIN Grade_Report gr ON st.StudentId = gr.StudentId JOIN Session s ON gr.SessionId = s.SessionId JOIN Module m ON s.ModuleId = m.ModuleId WHERE (st.StudentUsername = '".mysql_real_escape_string($studentid)."') ORDER BY c.CourseName, st.StudentUsername, m.ModuleName, s.SessionId "; Hi, I have an itinerary form at http://www.happydaysremovals.com/estimate.html Customers fill this in, and it uses phpmailer-fe to email the results to myself. I use a HTML .tpl file so I can make the output email look as I want. All that is fine, but I would like a volume calculator. Next to each item on the form, the customer enters the amount of that item, usually 1 or 2. If it was say a setee, I want to define that a setee = 30 cubic feet, for example. Then I want the calculator to calculate the total cubic footage for all the variables, and include it in the html email. I know with javascript this can be done, but I was hoping for a PHP result and for it to somehow work in with phpmailer-fe, for example: </style> <script language="JavaScript"> function write_this() { var setteelarge; var setteemedium; var setteesmall; var setteelarge2; var setteemedium2; var setteesmall2; var setteelargeresult; var setteemediumresult; var setteesmallresult; var total; setteelarge = document.form1.LargeSettee.value; setteemedium = document.form1.MediumSettee.value; setteesmall = document.form1.SmallSettee.value; setteelarge2 = 45 setteemedium2 = 31 setteesmall2 = 22 setteelargeresult = (setteelarge * setteelarge2); setteemediumresult = (setteemedium * setteemedium2); setteesmallresult = (setteesmall * setteesmall2); total = (setteelargeresult+setteemediumresult+setteesmallresult) document.form1.Total_Cubic_Feet.value = total } </script> Basically, I want to be able to include the cubic feet total value to also be emailed to me in the HTML email, but preferably all in PHP. At the moment, I get everyones itinerary, but want to be automatically be able to work out the cubic footage. Thanks This is a bit of a puzzle. Look at the sum and result below: Code: [Select] $markTotal += ($session['Mark'] / 100 * $session['SessionWeight']); Result on Browser Module: CHI2550 - Modern Database Applications 41.2 (this is $markTotal) Session: AAB 72(this is $session['Mark']) 20% (this is $session['SessionWeight']) (The percentage signs are just add ons) Session: AAE 67(this is $session['Mark']) 40% (this is $session['SessionWeight']) As you can see the answer to the calculation above is right, the answer is 41 .2 as it adds up the two session marks, divide by 100 and then times it by the total amount of the percentage. But I want to include a total mark where except it is out of the total session percentage (60% for above example), it is out of a 100% but I can not work as simple as that as in above example one session is worth more than other. I have worked out that the answer for the total mark of the above example out of 100% should be 69, but how do I achieve this in my calculation. Thank you and any help is much appreciated So how Dear All, I am trying to fetch the sum of a column for current date and subtract a value from the sum for currently selected record. The query i build works fine in MySql but when the same query i placed in php no result it's blank. Below is the query.
<?php //Calculation for no of paxs. $query2=mysqli_query($con,"SELECT SUM(noopaxs-gattl) FROM tblsupvisitor where date(EnterDate) = CURDATE() || gst = 'INH' || gst = 'IN' GROUP BY confno"); $calc_no_paxs_for_today=mysqli_fetch_row($query2); $gattl=$calc_no_paxs_for_today['gattl']; ?>
and her is the assignment to the textbox.
<div class="row form-group"> <div class="col col-md-3"> <label for="textarea-input" style="color: purple" class=" form-control-label"><strong>Total No. Of Adults</strong></label> </div> <div class="col-12 col-md-9"> <input name="gattl" id="gattl" rows="9" class="form-control" required="" value="<?php echo $gattl;?>"> </div> </div>
Any help in this regard will be highly appreciated.
Kind Regards, Naveed. When I use this: echo number_format(150 + 20.95 + .5, 2); ... I get 170.95. Yet on my calculator, 150 + 20.95 + .5 gives me 171.45. Why is that? The time dosen't calculate correctly!!! When the local time is 3:15pm on16th Nov 2010 - "Time Expired" dosen't show. When I echo $drawT-time() it shows 60000 odd. What's wrong here? $drawH = 15; $drawM = 15; $drawM = 11; $drawD = 16; $drawY = 2010; $cutoffT = 4; $drawT = mktime($drawH, $drawM, 0, $drawM, $drawD, $drawY); date_default_timezone_set("Australia/Melbourne"); if($drawT-time() < $cutoffT*60) { echo "Time Expired."; } Hi, I have an attendance system that calculates time in and time out for each day. I have a db field with time datatype that stores the total time for one day, say for example for today the total is 7:15:00 (7 hours and fifteen minutes). i am making a report to show all attendance records for a week. I need to show total of hours a week which is around 35-40 hours so how can this be done? screenshot of what i have. Edited March 15, 2020 by ramiwahdan typo error I have a table of members (18) with games played, won, drawn, lost and would like to know if its possible to have the points and percentage update automatically, example- ID Member Grade Played Won Drawn Lost Points % 1 Player name 142 13 1 10 2 6 46.15 My web-page is currently static and i go to http://math.about.com/library/weekly/aa061502a.htm fill in the games played and points and it gives the percentage, i have very little knowledge of php and by some miracle have managed to create a database using wamp and have extracted the data onto local host web page, my code as follows please let me know if i have any errors- Code: [Select] <?php require "connect.inc.php"; echo "<table width='700'> <tr> <th></th> <th>Member</th> <th>Grade</th> <th>Played</th> <th>Won</th> <th>Drawn</th> <th>Lost</th> <th>Points</th> <th>&#37;</th> </tr>"; $result = mysql_query("SELECT * FROM members"); while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['member'] . "</td>"; echo "<td>" . $row['grade'] . "</td>"; echo "<td>" . $row['played'] . "</td>"; echo "<td>" . $row['won'] . "</td>"; echo "<td>" . $row['drawn'] . "</td>"; echo "<td>" . $row['lost'] . "</td>"; echo "<td>" . $row['points'] . "</td>"; echo "<td>" . $row['percentage'] . "</td>"; echo "</tr>"; } echo "</table>"; ?> Please tell me how i can have the points and percentage update automatically and keep in mind im a novice with php. Best wishes, John Please help me calculate this according to the "if" condition. $scoreM['newtag'] + $scoreU['newPrice'] $SomeVar = 'currentPrice'; $queryU = "SELECT * FROM db1 WHERE bookprice = '".$SomeVar."'"; $resultU = mysql_query($queryU); $scoreU = mysql_fetch_assoc($resultU); echo $scoreU['newPrice']; echo $scoreU['weeklyScr']; echo $scoreU['priceX']; //// $WinVar = 'additionalAmount'; $query = "SELECT * FROM db2 WHERE booklist = '".$WinVar."'"; $result = mysql_query($query); $scoreM = mysql_fetch_assoc($result); echo $scoreM['newtag']; echo $scoreM['priceY']; if($scoreU['priceX']== $scoreM['priceY']) { $udatedValue = ($scoreM['newtag'] - $scoreU['newPrice']); echo(udatedValue); } else{ $udatedValue = ($scoreM['newtag'] + $scoreU['newPrice']); echo(udatedValue); } Good day! I've been stumbled into a situation wherein the user have predefined time (this will be the expiration time) and the system will have to compare the user time based on server time. I've done the job in getting the time with timezone inclusion using javascript var userDate = new Date(); // output : Tue Dec 06 2011 16:18:23 GMT+0800 (PHT) I passed that javascript value using ajax to the server, the problem I encounter is the compare the current server date with the userDate. Any solution? Thanks in advance. |