PHP - Future Date Function
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 Similar TutorialsHi, 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 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)); 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! 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! 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 Hi,
I have made a database linked with php that I use a html form for. The HTML form requests a particular date to retrieve, and the php form it is linked to then retrieves data from the MySQL database from that date.
My question is: I want there to be a restriction so that the retrieval can only be for dates before the present date (and certainly not any date in the future).
e.g. if it is 6th July 2020, then the database can only retrieve from the 5th July 2020 and before. (7th July 2020 onwards also is not allowed.) Is there a way I can do it? Anyone who can guide me to a particular code function or something of that sort - I would be deeply grateful as my searches have not come up fruitful. Edited July 10, 2020 by samanjclarity I'm getting this Time Zone error. Perhaps it's a compatibility issue with PHP 5.3. Looked all over for an answer without finding one. Here is the error message Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EST/-5.0/no DST' instead in /blocked.php on line 41 12/02/12 Here is the code. Line 41 is near the bottom, the one with the d,m,y. Perhaps the echo date (d/m/y") needs to be changed. Appreciate any help! Code: [Select] <table border="3" width="16%" align="center" cellspacing="0" bgcolor="#FF6600" bordercolor="red" bordercolordark="red" bordercolorlight="red"> <tr> <td width="176"> <p align="center"><?php // shows IP Number on Page echo $ip; ?> </p> </td> </tr> </table> <p align="center"><?php // Show the user agent echo 'Your user agent is: <b>'.$_SERVER['HTTP_USER_AGENT'].'</b><br />';?></p> [b]<h1 align="center"><?php echo date("d/m/y");?></h1>[/b] </td> </tr> </table [,code] I am doing somthing complicated with dates and I think I am making it harder than I should. I need to subtract "x" number of months from the current date, then create 2 dates in that month that represent the first day, and last day of the month. Then make it in a format that SQL can read to get the SUMS I need between those dates. My last 2 strtotimes are wrong and are giving me the 1969 dates. Code: [Select] function commiss($nummonth){ $repnum = $_SESSION['REPID']; $date = date("Y-m-d", strtotime("-" . $nummonth . "")); $time2 = " 00:00:01"; $time = " 23:59:59"; $date1 =date("Y-m-d", strtotime(date('m').'/01/'.date('Y'))); $date2 =date("Y-m-d", strtotime('-1 second',strtotime('+1 month',strtotime(date('m').'/01/'.date('Y'))))); $date1 = date("Y-m-d", strtotime("-" . $nummonth . "", $date1)); $date2 = date("Y-m-d", strtotime("-" . $nummonth . "", $date2)); $date1 = $date1 . $time2; $date2 = $date2 . $time; $string = "SELECT SUM(premium), SUM(repcom) FROM commission WHERE repnum = '$repnum' BETWEEN '$date1' AND '$date2'"; $sqltotal = mysql_query($string)or die (mysql_error()); $sqlprem = mysql_fetch_array('[SUM(premium)]'); $sqlcomm = mysql_fetch_array('[SUM(repcom)]'); echo "Premium: " . $sqlprem; echo "\n Rep Commission: " . $sqlprem; } Hello Again guys, I have varous dates stored in a database , these dates can look like this 2010-08-06 07/08/2010 07-08-2010 The problem is I dont know what format they are stored in.. What I need is a function which takes in 1 date at a time and returns it in a format I need it to be.. the format I need is 07/08/2010 thank you again for all you help I have been looking at thr date() but not been able to answer my qustion yet i just want to display the values form database which i have saved before and just want to be displayed when specific time comes as i told above in e.g if i have stored some thing like value let say ( 10,20,30,40 and so on ) in database now i just want a php code to display it on site but on specific time only like this, i time = 10:00am display value = 10 when time = 10:30am display value = 20 when time = 11:00am display value = 30 and so own simple. I am scraping Birthdays from a webpage that are in this format September 15, 1987 $age = 15; $page = source code of a html page; so far i have made this function How do i return the function as true if the date scaped makes the person over 15 and false if the person is younger? function checkForAge($page,$age) { preg_match('|Born on ([a-zA-Z]*\s[0-9]*,\s[0-9]*)\\\u003c\\\/span>|', $page, $match); if($match && count($match)>0) { echo "Match Found"; $dateOfBirth = str_replace(",","",$match[1]); // $dateOfBirth = date('d/m/Y', strtotime($dateOfBirth)); $dateOfBirth = strtotime($dateOfBirth); /* if("date of birth makes person over $age) { return true; } else { return false; } */ } How would you use the date function to display a birthday with an user's input? $date=date("Y-m-d H:i:s"); This is returning me the GMT time instead of EST. I get 15:26:08 as the time instead of 10:26:08. How can I get around this? Hi all, I want to include the date and time in the web page to display when a user logged into the site. I found a code.I want to know how it could modify with relevant to our local time? <?php $today = date("d M Y h:i A"); echo $today ?> Thanks, Hi, I have the following code which lists all the dates since October 5th 2007 until yesterday's date, and displays it as a link. This part works fine. What I want to do is omit the weekends, so the first few lines would read like so: 05/10/2007 08/10/2007 09/10/2007 10/10/2007 11/10/2007 12/10/2007 15/10/2007 Does anyone know how I can modify this code, or have any other methods of doing this? Code: [Select] <?php function dates_between($start_date, $end_date = false) { if ( !$end_date ) { $end_date = date("Y-m-d"); } $start_date = is_int($start_date) ? $start_date : strtotime($start_date); $end_date = is_int($end_date) ? $end_date : strtotime($end_date); $end_date -= (60 * 60 * 24 + 1); $test_date = $start_date; $day_incrementer = 1; do { $test_date = $start_date + ($day_incrementer * 60 * 60 * 24); echo '<a href="http://markets.ft.com/RESEARCH/markets/DataArchiveFetchReport?Category=CU&Type=WORL&Date=' . date("m/d/Y", $test_date) . '">' . date("d/m/Y", $test_date) . "\n</a><br>"; } while ( $test_date < $end_date && ++$day_incrementer ); } dates_between("2007-10-04"); echo "\n\n"; ?> Thanks, Dave Hi, I'm making an RSS feed http://dev.subverb.net/mixes_rss.php and as you see the date('r', $row['date']) function is not converting it. I've echo'd $row['date'] into the description to show what format the date is in (just mysql datetime. Am I missing something? Thanks hello i got this small function i`m working on to get the date of a month something like get current date - 1 but not sure how to handle jan month can someone help me please ? $month = date('m') - 1; $date_startt = date('Y').'-'.$luna.'-01'; $timestamp_start = strtotime($data_start); I am working on a project where I need PHP and mysql to perform calculations on dates, so I am storing them in the mysql format 2011-09-12, I am writing a custom function that will convert this into a date('M d Y') format, but all I get when I run my function is "1" This is my first custom function, so i am sure it is a simple fix, I am just at the end of my spectrum on functions. I can do this as an inline script, but will need this on various pages Code: [Select] function readableDateConvert($mysqlTime) { $phpTime = strtotime($mysqlTime); $readableTime = date('M d Y',$newTime); return $readableTime; } want something like: Code: [Select] date('F j, Y, g:i a') but in central timezone, how do I change the timezone to central? |