PHP - Date/time - Show Dates Not Found
I have a query that fetches all the dates in a date range then displays them in a Date:HH:MM;SS format. However when displayed sometimes there are missing Hours as I don't have data for them and I would like to display it. So right now I have something like this.
Date Column: Revenue_Column: 07/29/2010 00:00:00 $250.00 07/29/2010 01:00:00 $150.00 07/29/2010 03:00:00 $350.00 07/29/2010 04:00:00 $450.00 As you can see 02:00:00 is missing, how can I use php or possibly mysql to fill in that gap? I have tried creating an hours table and joining them and grouping by date however that doesn't seem to work. Any ideas? Similar Tutorialsi have a table that shows payments made but want to the payments only showing from a set date(06/12/14) and before this date i dont want to show
this is my sql that doesnt seem to work and is showing dates before the specified date.
.
"SELECT * FROM payments2014, signup2014, editprop2014 WHERE signup2014.userid = payments2014.payment_userid AND editprop2014.prop_id = signup2014.prop_id AND signup2014.userid !='page1' AND signup2014.userid !='page6' AND signup2014.userid !='page4' AND payments2014.payment_transaction_status !='none' AND payments2014.payment_transaction_status !='CANCELLEDa' AND payments2014.payment_type !='deposit' AND payments2014.payment_paid_timestamp NOT LIKE '%2012%' AND payments2014.payment_paid_timestamp NOT LIKE '%2011%' AND payments2014.payment_paid_timestamp >= '06/12/14' ORDER BY payments2014.payment_id DESC"i have some other parts in the statment but this one that should be filtering is host_payments2014.payment_paid_timestamp >= '06/12/14'thanks in advance Hi, I have a problem. i want to show the current date and time in my tables of the database. I want to show it because i want to show it on my report generated in php. By the way i do not have a "date" field in my form. Can anyone help me out? Thanks, Heshan. Hey guys, How would I go about subtracting Today from a previous day to find the difference? For example, I want to subtract TODAY from a previous date in my database, to determine if the difference is greater than 1 day. Any ideas? I tried doing the subraction in TIMESTAMPS, but when I convert the date back to Y-m-d H:i:s, I got some weird year and time. i have this small code but i will like to know add an echo that will say "No match found" if the search is not available in the database. Code: [Select] <?php $term = $_POST['term']; $sql = mysql_query("SELECT DISTINCT itemNumber, itemDesc, quantityHand, SUM(quantityHand) AS quantityHand FROM inventory where itemNumber like '%$term%' GROUP BY `itemNumber` ORDER BY `itemNumber`"); while ($row = mysql_fetch_array($sql)){ echo "<b>"; echo "</td><td style=\"text-align: center;\"><b>"; echo $row['itemNumber']; echo "</td><td style=\"text-align: center;\"><b>"; echo $row['itemDesc']; //echo "</td><td style=\"text-align: right;\">"; echo "</td><td style=\"text-align: center;\"><b>"; echo $row['quantityHand']; echo "</td></tr>"; echo "</b>"; } if (!$term) { print "No match found"; } ?> Hi... Good day! I have table that has a field from_date and to_date. Now I just want to know if how can I display as table format the dates between from_date to_date. Like this from_date: 2011-12-16 to_date: 2011-12-31 I want to display it: 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 // table format. Thank you Hi, I have a created comment system, now what i am after is when the comment is posted the time is posted in hidden format. All is going fine but what i don't know, what should the time be posted as example date(H:m:s) or... the result i want is time in minutes first e.g. commented 2 mins ago and increasing to hours after that days. Could some one kindly guide me in the right directions. PHP date and time function is not showing correct time on my local system I have the following php code date_default_timezone_set("Africa/Lagos"); $date = date('d-m-y h:i:s'); echo "Server Time ".$date ."<br>"; echo "The time is " . date("h:i:sa")."<br>"; $current_datetime = date("Y-m-d") . ' ' . date("H:i:s", STRTOTIME(date('h:i:sa'))); echo "Current time1: ".$current_datetime . "<br>";
Output
Server Time 21-05-21 09:55:39
Expected Output
Server Time 21-05-21 10:55:39
Any help would be appreciated. Edited May 21 by Ponel I have two text fields in a form. Both accepts dates. I'd like to check whether the second date provided is exactly one year in the future from the first provided date.
I can easily do this in PHP but since I need to do the check once the user leaves the second field, I have to resort to JavaScript, using onblur or something.
There are two issues I have.
1. Make sure that the strings provided are indeed dates (I would use strtodate() in PHP for this)
2. Regardless of month provided, making sure that the second date is exactly a year in the future of the already provided year
I've only captured the values and passed them to Date(). However, it can only handle european style, and if I enter 1981-06-16, the value returned is Jun 15 1981 17:00:00 which is obviously wrong.
Here is the simple broken code I have
var text1 = document.getElementById("text1"); var start_date = new Date(text1.value); var text2 = document.getElementById("text2"); var end_date = new Date(text2.value); alert(start_date);I need some guidance. I'm trying to wrap my head around how i should go about doing this. I have two dates...2011-05-03 and 2011-05-08. I want to write a function that creates an array of the days that consist of that date range. So say something like Code: [Select] <?php $start = "2011-05-03"; $end = "2011-05-08"; function get_days($start, $end) { //code to get the days } echo get_days($start, $end); //hopefully produce something like... $day['1'] = "2011-05-03"; $day['2'] = "2011-05-04"; $day['3'] = "2011-05-05"; $day['4'] = "2011-05-06"; $day['5'] = "2011-05-07"; $day['6'] = "2011-05-08"; anybody know any idea how to do something like this? Pretty sure i'm going to need the mktime() function to account for ranges going across months and years. I want to show a cookie of a referral's username on a sign up page. The link is like this, www.mysite.com/signup?ref=johnsmith. The cookie doesn't show if I go to that url page. But it does show up once I reload the page. So I'm wondering if it's possible to show the cookie the first time around, instead of reloading the page? Here is my code. // This is in the header $url_ref_name = (!empty($_GET['ref']) ? $_GET['ref'] : null); if(!empty($url_ref_name)) { $number_of_days = 365; $date_of_expiry = time() + 60 * 60 * 24 * $number_of_days; setcookie( "ref", $url_ref_name, $date_of_expiry,"/"); } else if(empty($url_ref_name)) { if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; } } else {} // This is for the sign up form if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; ?> <fieldset> <label>Referred By</label> <div id="ref-one"><span><?php if(!empty($user_cookie)){echo $user_cookie;} ?></span></div> <input type="hidden" name="ref" value="<?php if(!empty($user_cookie)){echo $user_cookie;} ?>" maxlength="20" placeholder="Referrer's username" readonly onfocus="this.removeAttribute('readonly');" /> </fieldset> <?php }
This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321426.0 I'm trying to do the following PHP. I have written it in English if (today's date) => date1 AND <= date2 then {display image1} elseif (today's date) => date3 AND <= date4 then {display image2} else {display image 13} There are 24 fixed dates and 13 fixed images. I have tried using combinations of strtotime(), replacing the date value with variables, hard coding the dates within the program. I don't seem to be able to get any combination to work properly. I'm sure it's just a syntax error but I can't see it. When I've searched the web all the answers I've found relate to dates within databases but as I only have 24 dates it seems a bit of overkill. I would appreciate any pointers to the correct method I might be able to use. The dates need only a day and month as I would like this to repeat year after year. <?php $today = strtotime(date('d-m')); if (strtotime($today) >= strtotime('28-10') && strtotime($today) <= strtotime('24-11')) {echo "<div>image1</div>";} elseif (strtotime($today) >= strtotime('25-11') && strtotime($today) <= strtotime('22-12')) {echo "<div>image2</div>" ;} elseif (strtotime($today) >= strtotime('23-12') && strtotime($today) <= strtotime('24-02')) {echo "<div>image3</div>" ;} else {echo "<div>image13</div>";} ?> The result I get from this is image1 appears on the web page but I would expect image3 as today is 22-01 Thank you in advance. Andrew I have date stored in database in any of the given forms 2020-06-01, 2020-05-01 or 2019-04-01 I want to compare the old date with current date 2020-06-14 And the result should be in days. Any help please? PS: I want to do it on php side. but if its possible to do on database side (I am using myslq) please share both ways🙂 Edited June 14, 2020 by 684425I have got a date field in my mysql database with events, and as you know date in MYSQL uses yyyy/mm/dd but I would first like to turn this around to dd/mm/yyyy but also turn this into for example "Tuesday - May 1990" would anyone like to point me into the right direction? Much appreciated! I would like to know the best practice to achieve the following: I have a list of dates related to live events for performing artists. When someone views the web page that contains a section to display the dates, I would only want to show the dates from today into the future and not show any dates from the past. What is the best way to accomplish this? Thanks in advance... OK So I've got a datepicker that sends a date in d/m/y format. My DB stores the data in Unix Timestamp Which I can convert the date to with strtotime however this does the exact date & time. All I want is the actual day. I've spent hours trying to convert this with just the day with mixed results... Thanks. I am having a problem with PHP displaying the correct date and time. It updates as it should, but is fast by 4min and is always displaying a date in 2004. I ran a basic php script to make sure the application im using itself is not wrong. go to lunenburgledger.com/time.php Anybody had any ideas on where to check? The system time on the Windows Server 2003 is correct. The only thing I can think of is that it was converted to a virtual machine on vmware esxi, but the system time stayed right. Any ideas? Thanks! I found this function and take no credit for it, I'm trying to get it to show HH:MM:SS when I have the total number of seconds, but nothing is showing on the screen function sec2hms ($sec, $padHours = false) { // start with a blank string $hms = ""; // do the hours first: there are 3600 seconds in an hour, so if we divide // the total number of seconds by 3600 and throw away the remainder, we're // left with the number of hours in those seconds $hours = intval(intval($sec) / 3600); // add hours to $hms (with a leading 0 if asked for) $hms .= ($padHours) ? str_pad($hours, 2, "0", STR_PAD_LEFT). ":" : $hours. ":"; // dividing the total seconds by 60 will give us the number of minutes // in total, but we're interested in *minutes past the hour* and to get // this, we have to divide by 60 again and then use the remainder $minutes = intval(($sec / 60) % 60); // add minutes to $hms (with a leading 0 if needed) $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ":"; // seconds past the minute are found by dividing the total number of seconds // by 60 and using the remainder $seconds = intval($sec % 60); // add seconds to $hms (with a leading 0 if needed) $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT); // done! return $hms; } The part of the code to show the data is below: Code: [Select] while ($row = mysql_fetch_array($result)) { $sec = time() - strtotime($row['starttime']); echo $sec; // print to screen to make sure $sec had a value sec2hms($sec); } Any guidance on where I went wrong? Hey, I need help with my date & time string. I need to edit it do show in a string + also use it for calculating things like when the date has passed. The string is like this: Code: [Select] <?php $string = '2011-01-01 00:00 AM'; ?> So i wanted to check if there was a function that can automatically convert it, so it would say for example: Quote Sunday, 1st of January 2011 00:00 AM But at the same time compare $string against server time to see if the date has expired? Hope you can help Hi! The below dropdown will show dates/times every 15 minutes from 12am to 11:45pm for only 1 day. I want it to show for 5 days, anyway I can do this? Below code: Code: [Select] $start = strtotime('12:00am'); $end = strtotime('11:45pm'); echo '<select name="time">'; for ($i = $start; $i <= $end; $i += 900) { echo '<option>' . date('F j, Y, \a\t g:i a', $i); } echo '</select>'; Thanks for any help. |