PHP - Date: Maximum Number Of Years Into The Future
I want to set a never expire date, so I figured I would set the date 99 years into the future. No dice. After trial and error, it appears you can only make it 25 years into futu
date("Y-m-d",strtotime("+25 years")); I wonder if it is the absolute date, or the number 25. If it is the maximum date (i.e. nothing after 2035) then I will have a problem with this code next year! Similar TutorialsHi i have this drop down list current the year is 2010 and downwards but i want to change the list to 2010 upwards u can notice on the 50-- so shows current year minus so current is 2010 to 61 how can i change 2010 to 2030 or sunfin?? echo '<select name="year_of_birth">',"\n"; $year = date("Y"); for ($i = $year;$i > $year-50;$i--) { if($i == $thisYear) { $s = ' selected'; } else { $s=''; } echo '<option value="' ,$i, '"',$s,'>' ,$i, '</option>',"\n"; } echo '</select>',"\n"; Hi, I am trying to get the number of days between the current date and a date in the future specified by column 'end_date'. The code I have seems to be working but it displays the number of days as a negative number, how do I change this to be a positive number? I have tried simply changing $days = $now - $end_date; to $days = $end_date - $now; but that doesn't work as I thought it would! Thanks in advance.. Code: [Select] $now = time(); $end_date = strtotime($row['end_date']); $days = $now - $end_date; echo floor($days/(60*60*24)); Hi everyone, I'm writing a science fiction wordpress blog set 10 years into the future. I basically need all posts to display as if they are 10 years from now. Eg. posts needs to display as: February 7, 2021 instead of February 7, 2011 This will be for every post that I write. How can I automatically add 10 years to every post date? (And where would I put that code?) Currently, the wordpress php is calling the date with `<?php the_time(__('M j, Y')) ?>` I realise it's a bit of an odd request, but it's necessary for this particular project. I know it's possible - but I'm brand new to php and am not sure how. =) I hope someone out there can help. It would be very much appreciated. many thanks in advance Luke I can determine 3 years from today, but How do determineo 3 years from march 1st? So I want to echo out "3/1/2013"? Thanks! 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 Hi, I am using this function to output a list of dates for every friday over the next 12months. This is working fine. Code: [Select] [php] //function function nextWeeksDay($date_begin,$nbrweek) { $nextweek=array(); for($i = 1; $i <= $nbrweek; $i++) { // 52 week in one year of course $nextweek[$i]=date('Y-m-d', strtotime('+'.$i.' week',$date_begin)); } return $nextweek; } /// end function /// example of a select date // var $date_begin=strtotime('this Friday'); $nbrweek=52; // call function $result=nextWeeksDay($date_begin,$nbrweek); // Insert //$date1=date('Y-m-d', $date_begin); for($i = 1; $i <= $nbrweek; $i++) { //$date=$result[$i]; echo $result[$i]."<br/>"; } [/php] My problem is that when I alter the code to try and get the date for every second Friday for the next year the script freezes. Code: [Select] [php] //function function nextWeeksDay($date_begin,$nbrweek) { $nextweek=array(); for($i = 2; $i <= $nbrweek; $i+2) { // 52 week in one year of course $nextweek[$i]=date('Y-m-d', strtotime('+'.$i.' week',$date_begin)); } return $nextweek; } /// end function /// example of a select date // var $date_begin=strtotime('this Friday'); $nbrweek=52; // call function $result=nextWeeksDay($date_begin,$nbrweek); // Insert //$date1=date('Y-m-d', $date_begin); for($i = 2; $i <= $nbrweek; $i+2) { //$date=$result[$i]; echo $result[$i]."<br/>"; } [/php] I really don't understand why?? Does anyone know why? Thanks I was wondering if there was a way to have the MAX function NOT return a Date that is more than 2 days into the future (from the current day)? If there is a Date that is more than 2 days into the future I would like to return the one closest to the current day. Here is the code I have: Code: [Select] <?php mysql_connect("local", "xxx", "xxx") or die(mysql_error()); mysql_select_db("pricelink") or die(mysql_error()); // Get a specific result from the "ft9_fuel_tax_price_lines" table $query ="SELECT ItemNumber,TableCode,Cost, MAX(`Date`) as `max_date`, MAX(`Time`) as 'max_time' FROM `ft9_fuel_tax_price_lines` GROUP BY `ItemNumber`,`TableCode`"; $result = mysql_query($query) or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>ItemNumber</th> <th>TableCode</th> <th>Date</th> <th>Time</th> <th>Cost</th> </tr>"; // keeps getting the next row until there are no more to get while($row=mysql_fetch_array($result)) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['ItemNumber']; echo "</td><td>"; echo $row['TableCode']; echo "</td><td>"; echo $row['max_date']; echo "</td><td>"; echo $row['max_time']; echo "</td><td>"; echo $row['Cost']; echo "</td></tr>"; } echo "</table>"; ?> Any help would be appreciated. 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 Hi, This one has been driving me up the wall, so hopefully some kind person can help me. I'm trying to make a validation script. $creststartdate comes in from a form as a UK formatted date (d/m/Y), and if $creststartdate is more than a month ahead of today, then it gets rejected. here's the code I have now... Code: [Select] $today = date("m/d/y"); $onemonth = strtotime ('+1 month', strtotime($today)); $nextmonth = date ('d/m/Y', $onemonth); $csd = date("m/d/y", $creststartdate); $strcsd = strtotime($csd); $newdate = date ('d/m/Y', $strcsd); if ($newdate > $nextmonth) { $creststartdatefailed = "The Crest Start Date cannot be more than 1 month in the future."; $creststartdatevalid = "NO"; } As it stands, this version of the code means that nothing is getting rejected. Please help?? Cheers I am having trouble showing reports for a given date range. Currently if I specify something like 11/03/2010 to 11/05/2010 I get results for all years within that month and day such as I may get results for 11/03/2008 11/03/2009 11/03/2010 11/04/2008 11/04/2009 11/04/2010 11/05/2008 11/05/2009 11/05/2010. I am using the following code $result = mysql_query("SELECT * FROM report WHERE date>='$date_begin' and date<='$date_end' ORDER BY 'date'",$db); I use the following format in my date feild mm/dd/yyyy 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 guys! This will seem complex but I really need your help If a have a variable with a date value (i.e. $a = '23/10/2011') How do you work out the week number of that date? Thanks Hello, I am writing a CMS for a sports organization league. One of my pages grabs values from the database using only the current week. What I want to do is when the admin enters in a game date, I want it to automatically find the week number for the date they entered. I haven't been able to find anything online that works for me. Any help would be great! Thanks Hi guys I'm kinda stuck..so hopefully you guys can lend me a hand I've got an array containing date elements ("Y-m-d")... I'm trying to output some data into googlecharts..so i need to count how many elements that are in the array with todays date -1 day, todays date-2 days...todays date -3days etc... Up until a set number of days (for example 7 days, 14 days etc).. Any advice on how to go about to achieve this? I'm getting the dreaded " Invalid parameter number: number of bound variables does not match number of tokens" error and I've looked at this for days. Here is what my table looks like:
| id | int(4) | NO | PRI | NULL | auto_increment | | user_id | int(4) | NO | | NULL | | | recipient | varchar(30) | NO | | NULL | | | subject | varchar(25) | YES | | NULL | | | cc_email | varchar(30) | YES | | NULL | | | reply | varchar(20) | YES | | NULL | | | location | varchar(50) | YES | | NULL | | | stationery | varchar(40) | YES | | NULL | | | ink_color | varchar(12) | YES | | NULL | | | fontchosen | varchar(30) | YES | | NULL | | | message | varchar(500) | NO | | NULL | | | attachment | varchar(40) | YES | | NULL | | | messageDate | datetime | YES | | NULL |Here are my params: $params = array( ':user_id' => $userid, ':recipient' => $this->message_vars['recipient'], ':subject' => $this->message_vars['subject'], ':cc_email' => $this->message_vars['cc_email'], ':reply' => $this->message_vars['reply'], ':location' => $this->message_vars['location'], ':stationery' => $this->message_vars['stationery'], ':ink_color' => $this->message_vars['ink_color'], ':fontchosen' => $this->message_vars['fontchosen'], ':message' => $messageInput, ':attachment' => $this->message_vars['attachment'], ':messageDate' => $date );Here is my sql: $sql = "INSERT INTO messages (user_id,recipient, subject, cc_email, reply, location,stationery, ink_color, fontchosen, message,attachment) VALUES( $userid, :recipient, :subject, :cc_email, :reply, :location, :stationery, :ink_color, :fontchosen, $messageInput, :attachment, $date);"; And lastly, here is how I am calling it: $dbh = parent::$dbh; $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); if (empty($dbh)) return false; $stmt = $dbh->prepare($sql); $stmt->execute($params) or die(print_r($stmt->errorInfo(), true)); if (!$stmt) { print_r($dbh->errorInfo()); }I know my userid is valid and and the date is set above (I've echo'd these out to make sure). Since the id is auto_increment, I do not put that in my sql (though I've tried that too), nor in my params (tried that too). What am I missing? I feel certain it is something small, but I have spent days checking commas, semi-colons and spelling. Can anyone see what I'm doing wrong? Hi Guys, In a form within PHP coding i can get the the next 10 years with the following code: Code: (php) [Select] <?php $date_future = date("Y", strtotime('+10 year')); $date_year = date("Y"); for($i=$date_year;$i<$date_future;$i++){ if($date_year == $i){ echo "<option value=\"$i\" selected=\"selected\">$i</option> \n"; } else { echo "<option value=\"$i\">$i</option> \n"; } } ?> I have tried to mess about with the same code and try and get it to work for the last 10 years without any luck. He's what i did: Code: (php) [Select] <?php $date_past = date("Y", strtotime('-10 year')); $date_year = date("Y"); for($i=$date_year;$i>$date_past;$i++){ if($date_year == $i){ echo "<option value=\"$i\" selected=\"selected\">$i</option> \n"; } else { echo "<option value=\"$i\">$i</option> \n"; } } ?> I would appreciate any help with this. Ok so here is my code. Ignore the $_POST['dobm']. That is part of the whole script. All I want to know is how to set the list from 1998 to 1911 in descending order. I already tried making $i = 1998 and make $i - 1 til $i >= 1911. It seems to go in an infinite loop when I do that. Code: [Select] <?php for($i = 1911; $i <= 1998; $i++) { if ($_POST['dobm'] == $i) { echo '<option selected="selected" value="'.$i.'">'.date('Y', mktime(0,0,0,0,0,$i+1)).'</option>\n'; } else { echo '<option value="'.$i.'">'.date('Y', mktime(0,0,0,0,0,$i+1)).'</option>\n'; } } ?> I am searching the database for items that are plaques. There are different years of plaques. I find all the plaques sorted by year. My display puts them in rows of 4 max. What I want is to display them by year with a different year on a different line. Right now there are 4 (1963), 3 (1965), 1 (1978) all bunched together. 1963, 1963, 1963, 1963, 1965, 1965, 1965, 1978 What I want is: 1963, 1963, 1963, 1963, 1965, 1965, 1965, 1978, Any help would greatly be appreciated. <?php include 'config0.php'; $search=$_GET["search"]; // Connect to server and select database. mysql_connect($dbhost, $dbuser, $dbpass)or die("cannot connect"); mysql_select_db("$dbname")or die("cannot select DB"); $result = mysql_query("SELECT * FROM table1 WHERE plaques LIKE '%$search%' ORDER BY year") or die(mysql_error()); // store the record of the "" table into $row //$current = ''; // keeps getting the next row until there are no more to get if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 4; echo "<table align=center>"; echo "<br>"; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; echo "<td align=center>"; ?> <div style="float: left;"> <div><img src="<?php echo $tn; ?>"></div> </div> <?php echo "</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i > 0) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; echo '</tr>'; } mysql_close(); ?> </table> How can i group the data by year to build the graph I need the data to be like so 2012 0 - total customers 0 - total customers 0 - total customers 0 - total customers 0 - total customers 9 - total customers 5 - total customers 3 - total customers 5 - total customers however i only have this data Code: [Select] total_customers month year 1 Aug 2011 9 Oct 2011 8 Nov 2011 4 Dec 2011 4 Jan 2012 so i need to make it show 0 for the months i dont have data for Code: [Select] <div id="dash_chart" class="portlet x9"> <div class="portlet-header"> <h4>Customer Growth</h4> <ul class="portlet-tab-nav"> <li class="portlet-tab-nav-active"><a href="#tab1" rel="tooltip" title="Customers">Customers </a></li> <li class=""><a href="#tab2" rel="tooltip" title="Sales over last 48 hours.">Sales </a></li> </ul> </div> <!-- .portlet-header --> <div class="portlet-content"> <div id="tab1" class="portlet-tab-content portlet-tab-content-active"> <?php echo '<table class="stats" title="area" width="100%" cellpadding="0" cellspacing="0"> <caption>Customer Base Growth</caption> <thead> <tr>'; $monthNames = Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); $i = 0; foreach ($monthNames as $month){ echo '<th>'.$month.'</th>'."\n"; } echo '</tr> </thead>'; $q = "SELECT count(cus_id) as total_customers, DATE_FORMAT(sign_date, '%b') as month, YEAR(sign_date) as year FROM customers GROUP BY YEAR(sign_date), MONTH(sign_date) ORDER BY sign_date ASC"; $r = @mysqli_query ($dbc, $q); $data = array(); if (mysqli_affected_rows($dbc) >= 1) { echo '<tbody> <tr> <th>2011</th>'; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { } } echo '</tr>'; ?> <tr> <th>2012</th> <td>3</td> <td>4</td> <td>2</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>3</td> <td>5</td> <td>3</td> <td>9</td> </tr> </tbody> </table> Hello All, I have a News database in which articles are entered in. Right now all the stories are being display in one big page with every story on it. What I would like to do is to create an "archive" in which it automatically organizes the stories by their date. For example. 2011 February January 2010 December November October September etc... etc... I have a datetime field for the database, and I know how to do this all manually, but I can't figure out how to make it automatically add a month each month. It would be too much maintanence to have to update this every month. I also don't know what this would be called, so I don't even know what to search for. I've tried blog and news, but doesn't seem to be what I want. Any help would be appreciated! |