PHP - Select Tomrows Date
Hi,
How can I check mysql date/time field for all records with tommorows date.. ? Thanks Similar TutorialsI have a calendar select date function for my form that returns the date in the calendar format for USA: 02/16/2012. I need to have this appear as is for the form and in the db for the 'record_date' column, but I need to format this date in mysql DATE format (2012-02-16) and submit it at the same time with another column name 'new_date' in the database in a hidden input field. Is there a way to do this possibly with a temporary table or something? Any ideas would be welcome. Doug hi, what is the proper way to to $now $next tuesday select * where date is between now and next tuesday thanks all So I have this program I purchased and it allows me to create custom form fields. I have been trying to create a date select box but have been struggling because I am just learning php. I was wondering if someone could lend a hand. I will try and give as much info as i can. First I will show a picture of the custom field box and then i will give the description of both boxes that the company gave me. Next i will give you the php code i have been trying to work with. Please if my code is not the best then i will take any advice. I found the code for the date selector online. Parsed Default Value - You may specify a variable or a function as the default value; for example $_SERVER[HTTP_USER_AGENT] or mktime() Parsed PHP Code - You can specify actual PHP code that will be used to return a variable. // You should assign the value you wish to use to the variable $str. Code: [Select] <?PHP FUNCTION buildDate($name, $m, $d, $y) { $date = DATE("m-d-Y",STRTOTIME("now")); $date_array = EXPLODE("-",$date); $now_m = ""; $now_d = ""; $now_y = ""; $month = '<select class="small" name="'.$name.'_month">'; $month .= '<option value="" selected disabled>mm</option>'; FOR ($i=1;$i<=12;$i++) { IF ( $m != "" ) { IF ( $m == $i ) { $now_m = "selected"; } }ELSEIF ( $m == "0" ) { $now_m = ""; }ELSE{ IF ( $date_array[0] == $i ) { $now_m = "selected"; } } $month .= '<option value="'.$i.'" '.$now_m.'>'.$i.'</option>'; $now_m = ""; }//END month for loop $month .= '</select>'; $day = '<select class="small" name="'.$name.'_day">'; $day .= '<option value="" selected disabled>dd</option>'; FOR ($i=1;$i<=31;$i++) { IF ( $d != "" ) { IF ( $d == $i ) { $now_d = "selected"; } }ELSEIF ( $d == "0" ) { $now_d = ""; }ELSEIF ( $d == $i ) { $now_d = "selected"; }ELSE{ IF ( $date_array[1] == $i ) { $now_d = "selected"; } } $day .= '<option value="'.$i.'" '.$now_d.'>'.$i.'</option>'; $now_d = ""; }//END day for loop $day .= '</select>'; $year = '<select class="small" name="'.$name.'_year">'; $year .= '<option value="" selected disabled>yyyy</option>'; FOR ($i=GMDATE("Y"); $i <=SUBSTR(get330Date(),0,4); $i++) { IF ( $y != "" ) { IF ( $y == $i ) { $now_y = "selected"; } }ELSEIF ( $y == "0" ) { $now_y = ""; }ELSEIF ( $y == $i ) { $now_y = "selected"; }ELSE{ IF ( $date_array[2] == $i ) { $now_y = "selected"; } } $year .= '<option value="'.$i.'" '.$now_y.'>'.$i.'</option>'; $now_y = ""; }//END year for loop $year .= '</select>'; //------------------------------------------- ECHO $month." ".$day." ".$year; }//END buildDate function // ------------------------------------ FUNCTION get330Date() { RETURN DATE("Y-m-d", MKTIME(0, 0, 0, SUBSTR(GMDATE("Y m d"),5,2), SUBSTR(GMDATE("Y m d"),8,2) + 330, SUBSTR(GMDATE("Y m d"),0,4)))."<br />"; } ?> I might just be totaly wacked here with what i am trying to do but i am sure someone will tell me one way or the other. lol hello with tis button i generate some statistics from mysql if(isset($_POST['sub1'])) { $result = mysql_query("SELECT servitoros1, COUNT(*) from history WHERE serv LIKE '%be%' group by serv1"); while($row = mysql_fetch_row($result)) { echo "<tr>"; foreach($row as $cell) echo "<td ALIGN=\"center\">$cell<FONT></td>"; echo "</tr>\n"; } mysql_free_result($result); } but each record have datetime field!! so how can i set this display betwean 2 selectable datetimes e.g. from 2/2/2011 15:45 to 3/2/2011 23:59 Hi all, I have done a script that works fine on a single basis... SELECT * FROM company WHERE so <> 0 AND so_active = 'yes' AND DATE_FORMAT(so_start_date, '%e') = '18' ORDER BY company_name ASC The problem I have is when I try to do a range... SELECT * FROM company WHERE so <> 0 AND so_active = 'yes' AND DATE_FORMAT(so_start_date, '%e') BETWEEN '5' AND '26' ORDER BY company_name ASC It should return at least 1 result as I am looking for '18', any help would be much appreciated. Many Thanks. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=309828.0 I have 2 tables I have settup called Users_Messages and Users_Message_Replies inside each of these tables I have a row called DateSent, I'm trying to select from both of these tables and only display the latest Sent item by ID and order them all by date. I can get it to display the items correctly using the below code, but I can't get them to order correctly by the latest date in both of the Tables. Code: [Select] $page_query = mysql_query(" SELECT MessageID, DateSent FROM Users_Messages WHERE ToID = '$user_ID' UNION SELECT MessageID, DateSent FROM Users_Messages WHERE FromID = '$user_ID' ORDER BY DateSent DESC "); while ($replycheck = mysql_fetch_assoc($page_query)){ $message_idmainnew = $replycheck['MessageID']; $date = $replycheck['DateSent']; $sql2 = "SELECT MainMessageID FROM Users_Message_Replies WHERE MainMessageID = '$message_idmainnew '"; $sql_result2 = mysql_query($sql2); $replycheck2 = mysql_fetch_assoc($sql_result2); $newreplyID = $replycheck2['MainMessageID']; $sql4 = "SELECT MessageID FROM Users_Messages WHERE MessageID= '$message_idmainnew'"; $sql_result4 = mysql_query($sql4); $messagecheck2 = mysql_fetch_assoc($sql_result4); $newmessageID = $messagecheck2['MessageID']; if ($newreplyID == NULL){ $sql2 = "SELECT * FROM Users_Messages WHERE MessageID= '$newmessageID' ORDER BY DateSent ASC"; $sql_result2 = mysql_query($sql2); $message_row = mysql_fetch_assoc($sql_result2); $message_01 = $reply_row['Message']; $date = $reply_row['DateSent']; $date1 = strtotime($date); $datemain = date('F j, Y, g:i a', $date1); }else{ $sql2 = "SELECT * FROM Users_Message_Replies WHERE MessageID= ' $newreplyID ' ORDER BY DateSent DESC"; $sql_result2 = mysql_query($sql2); $reply_row = mysql_fetch_assoc($sql_result2); $message_01 = $reply_row['Message']; $date = $reply_row['DateSent']; $date1 = strtotime($date); $datemain = date('F j, Y, g:i a', $date1); } { Is there an easier way to do this? And how would I get the dates to line up, with a Join? Thanks. I have database "raj" with table "pagination"
In table pagination have "id", "actualtime" and "created" field
id - auto_increment actualtime- varchar created- datetime
that looks like this CREATE TABLE pagination( id int auto_increment, actualtime varchar(55), created datetime )
I want to display all rows which are created on todays date and will display from today upto yesterday at 06:00 pm. after that the content will be refreshed based on based on a DATETIME field called 'created' that holds the date and time of each record's creation.
this is my query to fetch rows but it display value after 06:00 pm on yesterday but i want to display all data before 06:00 pm from currentdate. After 06:00 pm data will be refreshed and clear. plz help me......
SELECT actualtime FROM pagination WHERE created BETWEEN date_add(date_sub(curdate(), INTERVAL 1 day), INTERVAL 18 hour) AND curdate()";
is it possible to do something like Code: [Select] $today = date("Y-m-d"); $result = mysql_query("SELECT * FROM staff where date = '.$today.' "); also, is it normal for the first entry in the database not to be displayed? i have 6 entries in a table and only 2-6 are shown. when i changed the id for 1 to 7, it only displayed 3-7. Ok basic setup is Table name = unit_data I have a field unit_paid_date colum type = DATE unit_paid_date = 2011-03-02 thats yyyy-mm-dd lets say for example the DueDate is the Second of every month I need to select all records from unit_data that are PAST DUE so if the last paid date is 2011-01-02 that record will pop up as PAST DUE BUT if that paid date is say 2011-03-10 it will not be shown because the invoice was paid Ahead of due date I had this almost working properly -- but can use any help you guys offer. I was attempting to use mysql WHERE queries and do checks against paid_date but failed Thanks My query is a fixtures list for my local sports team- There seems little point including fixtures from the past as they are in a results query anyway. I'm ordering by date (see below) but how can I remove the ones already past? $query = "SELECT * FROM fix10 ORDER BY Date"; TIA Nick 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 Hello. I'm new to pHp and I would like to know how to get my $date_posted to read as March 12, 2012, instead of 2012-12-03. Here is the code: Code: [Select] <?php $sql = " SELECT id, title, date_posted, summary FROM blog_posts ORDER BY date_posted ASC LIMIT 10 "; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { $id = $row['id']; $title = $row['title']; $date_posted = $row['date_posted']; $summary = $row['summary']; echo "<h3>$title</h3>\n"; echo "<p>$date_posted</p>\n"; echo "<p>$summary</p>\n"; echo "<p><a href=\"post.php?id=$id\" title=\"Read More\">Read More...</a></p>\n"; } ?> I have tried the date() function but it always updates with the current time & date so I'm a little confused on how I get this to work. Alright, I have a Datetime field in my database which I'm trying to store information in. Here is my code to get my Datetime, however it's returning to me the wrong date. It's returning: 1969-12-31 19:00:00 $mysqldate = date( 'Y-m-d H:i:s', $phpdate ); $phpdate = strtotime( $mysqldate ); echo $mysqldate; Is there something wrong with it? I have tried a large number of "solutions" to this but everytime I use them I see 0000-00-00 in my date field instead of the date even though I echoed and can see that the date looks correct. Here's where I'm at: I have a drop down for the month (1-12) and date fields (1-31) as well as a text input field for the year. Using the POST array, I have combined them into the xxxx-xx-xx format that I am using in my field as a date field in mysql. <code> $date_value =$_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']; echo $date_value; </code> This outputs 2012-5-7 in my test echo but 0000-00-00 in the database. I have tried unsuccessfully to use in a numberof suggested versions of: strtotime() mktime Any help would be extremely appreciated. I am aware that I need to validate this data and insure that it is a valid date. That I'm okay with. I would like some help on getting it into the database. hirealimo.com.au/code1.php this works as i want it: Quote SELECT * FROM price INNER JOIN vehicle USING (vehicleID) WHERE vehicle.passengers >= 1 AND price.townID = 1 AND price.eventID = 1 but apparelty selecting * is not a good thing???? but if I do this: Quote SELECT priceID, price FROM price INNER JOIN vehicle....etc it works but i lose the info from the vehicle table. but how do i make this work: Quote SELECT priceID, price, type, description, passengers FROM price INNER JOIN vehicle....etc so that i am specifiying which colums from which tables to query?? thanks (continuing from topic title) So if I set a date of July 7 2011 into my script, hard coded in, I would like the current date to be checked against the hard coded date, and return true if the current date is within a week leading up to the hard coded date. How could I go about doing this easily? I've been researching dates in php but I can't seem to work out the best way to achieve what I'm after. Cheers Denno Hi, I have a job listing website which displays the closing date of applications using: $expired_date (This displays a date such as 31st December 2019) I am trying to show a countdown/number of days left until the closing date. I have put this together, but I can't get it to show the number of days. <?php $expired_date = get_post_meta( $post->ID, '_job_expires', true ); $hide_expiration = get_post_meta( $post->ID, '_hide_expiration', true ); if(empty($hide_expiration )) { if(!empty($expired_date)) { ?> <span><?php echo date_i18n( get_option( 'date_format' ), strtotime( get_post_meta( $post->ID, '_job_expires', true ) ) ) ?></span> <?php $datetime1 = new DateTime($expired_date); $datetime2 = date('d'); $interval = $datetime1->diff($datetime2); echo $interval->d; ?> <?php } } ?> Can anyone help me with what I have wrong? Many thanks Hi, Currently I am making a module for joomla. every article has an publish date, if the article was published in 7 days ago, it will displayed as "article in last week", My idea is to use today's date - publish date, if the result is greater than 7 and smaller than 14, the article will be displayed as "article in last week. Any one know how to write this code? Here is what I have got, but not working. <?php $todays_date = date("Y-m-d"); $result = mysql_query("select * from jos_content where $test between $todays_date-14 and $todays_date-7"); while($row = mysql_fetch_array($result)) { echo "$todays_date - $row[title]"; } ?> Hi there, I have a string '12/04/1990', that's in the format dd/mm/yyyy. I'm attempting to convert that string to a Date, and then insert that date into a MySQL DATE field. The problem is, every time I try to do so, I keep getting values like this in the database: 1970-01-01. Any ideas? Much appreciated. |