PHP - Retrieve Date Problem
I have a form where you can pick all the days in the week. When the form is posted my code finds the date of the day you picked that most recently went by. Then the code takes that date, and echos the date of every day of the week that you picked that comes after that date for a year.
But for some reason he thinks we're in 2009, even though i know the date puts out that we're in 2010. Here's the code: <?php //function if(isset($_POST['submit'])) { function nextWeeksDay($date_begin,$nbrweek) { $nextweek=array(); for($i = 1; $i <= $nbrweek; $i++) { // 52 week in one year of course $nextweek[$i]=date('d-m-y', strtotime('+'.$i.' week',$date_begin)); } return $nextweek; } //Get what user posted as day, and find the date of the past day gone. $roday = $_POST['day']; echo $roday; echo date('d-m-y',strtotime('last ' . $roday)); $sistdag = date('d-m-y',strtotime('last ' . $roday)); /// end function /// example of a select date // var $date_begin = strtotime($sistdag); //D Day Month Year - like function format. $nbrweek=52; // call function $result=nextWeeksDay($date_begin,$nbrweek); // Preview for($i = 1; $i <= $nbrweek; $i++) { echo '<br> - '.$result[$i]; } } ?> All help appreciated! Similar Tutorialshi i have a mysql table with upddate and updtime field as follows: upddate updtime 2011-02-25 11:03:05 2011-01-28 08:01:09 2011-02-20 07:00:08 2011-02-15 06:10:02 2011-02-05 10:21:04 2011-02-09 10:20:25 the data types for upddate is mysql date and for updtime its mysql time In my php page i use Code: [Select] <?php echo $date = date("d M Y",strtotime($row_rs1['upddate'])); ?> to retrieve date and the results displays as 25 Feb 2011. And for time right now im using Code: [Select] <?php echo $row_rs1['updtime']; ?> which displays time as 11:03:05 I want to display time as HH:MM only, how can i do it? 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 the date stored in my datrabase like this: 2010-04-03 I am then outputting the date like this: Sat 13 Nov This is done using this code: list($year,$month,$day) = explode('-',$Coursedate); $time_stamp = mktime(0,0,0,$month,$day); $Coursedate2 = date("D d M",$time_stamp); The problem I have come across is when listing a date for next year. The database has a value of 2011-01-29 which is a Saturday but it is outputting it as a Friday: Fri 29 Jan The 29th of January 2010 is a Friday but 2010 is a Saturday. Any idea what is wrong with the code? Hi Guys...i have this problem... I have this page where user can type in their date of birth...I would like to convert the date of birth input by the user to the DATA format which is defined by phpmyadmin (YYY-MM-DD) so that i can put into the database... My main objective of this is to calculate age... I have this form to allow use to type date of birth: Code: [Select] <label for="dob">D.O.B.: </label> <input type="text" name="dob" id="dob" class="regfields"/> This is to store the input to a variable: Code: [Select] $adddob = $_POST['dob']; and finally this query to insert all the input into the database: Code: [Select] $query = "insert into emp (FNAME, LNAME, CDSID, PAYNO, MAIL , TELNO , DOB , BRANCH , LICNO , CLASS , VFROM , VTO , EID , PASS , PIN) values ('$addfname','$addlname','$addcdsid','$addpayno','$addmail','$addtelno','$adddob','$addbranch','$addlicno','$addclass','$addvfrom','$addvto','$addeid','$addpassword','$addpin')"; Thanks in advance...If this is possible then I will set my dob column to the DATA format... Code: [Select] <?php $dayNames = array("Nedelja", "Ponedeljak", "Utorak", "Srijeda", "Četvrtak", "Petak", "Subota"); $dan = $dayNames[date('N')]; echo $dan.", ".date('d.m.Y.') ; ?> This is my code for showing days in my language, but it works on every day except sunday! Does anybody have any clue? Thanks! I am trying to get this script to display the date like Dec 17, 2010 and have the search function work too. If I try to change the date the search malfunctions and if I take the date function away the date is 2010 12 17 I thought we had this nailed down the other day but in my excitement I neglected to test the city search. Here is the script. <?php $find = trim($_GET['find']); $field = $_GET['field']; if($find && $field) { // we have search form submitted // check for values to prevent sql injection $valid_fields = array("venue_state", "venue_city", "start_date"); if(!in_array($field, $valid_fields)) die("Error: Invalid field!"); //connect mysql_connect("localhost", "arts_cshow", "TrPh123Yuo") or die(mysql_error()); mysql_select_db("arts_shows") or die(mysql_error()); echo "<h2>Search Results for $find in $field</h2>\n"; $find = addslashes($find); $result = mysql_query("SELECT * FROM craft_shows WHERE $field LIKE '%$find%'"); if(mysql_num_rows($result) == 0) { echo "<p>0 matches found.</p>"; } else { echo "<table><tr><td class=\"shows\">"; $sql = "SELECT *, DATE_FORMAT(`start_date`, '%b %e, %Y') AS s_date FROM craft_shows"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { echo "<a href='/show_submits/show_detail.php?id={$row['id']}'>Details</a>\n"; echo $row['venue_state'] . " {$row['s_date']} {$row['show_name']} {$row['venue_city']}<br>\n"; } echo "</td></tr></table>\n"; } } ?> thanks Hi all.. I'm grabbing the following date format from an rss feed: Sun, 16 Jan 2011 00:00:00 -0800 What's the best way to strip away the first 5 characters (Sun, ) and the last 15 characters ( 00:00:00 -080)... but still keeping this as a date (not a string) to store in my database? Thanks in advance for any ideas! //$start_point = '2014-07-22'; $lastday = date('t',strtotime($start_point)); $month_val = date('n',strtotime($start_point)); echo "Last day: ". $lastday . "<br/>"; echo "Month: ". $month_val . "<br/>";I have a problem with a date value read from a MySQL database table into a PHP variable but when manipulating the vale to determine the month of the date, unexpected results appear. I am not sure what causes this but I suspect PHP is not properly handling date to string conversion. The output from the code shows 1 as the month when it should be 7. Hower the line of code with the comment "//$start_point = '2014-07-22' if added in give the correct result. When the value of the variable "start_point" is printed, it gives the value "2014-07-22". Please see the code Telly I have such a little code. If I echo $order_date, I receive normal date in YYYY-MM-DD format. But when I use $order_date in mysql query it is not showing me anything. I do not receive any error or warning also. Please help me. $query = "SELECT Product,Amount FROM orders WHERE Date='$order_date'"; $result = mysql_query($query) or die(mysql_error()); while($products_list = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $products_list["Product"] . "</td>"; echo "<td>" . $products_list["Amount"] . "</td>"; echo "</tr>"; } Hi, I'm preparing a code for an automated email, but the date time is not working correctly. I wanted to do a cron scheduler that emails people twice a day - 9am and 9pm. 9am sends email about records logged starting 9pm yesterday to 9am, while 9pm sends email about records logged from 9:01am to 9:00pm. The database uses date/time, so I was doing an if statement of date time, but I wasn't getting the result I wanted. Sometimes the $now time is not within the yesterday 9pm to the 9pm today range. I don't know what I'm doing wrong, but I'm sure that it has something to do with the if statement, as the some of the $now time enters the else statement Here is my code: <?php $today = date('Y-m-d 00:00:00'); $nineyesterday = date('Y-m-d H:i:s', mktime(date("H") - (date("H") + 6), date("i") - date("i"), date("s") - date("s"), date("m") , date("d"), date("Y"))); $now = date('Y-m-d H:i:s', mktime(date("H") + 13, date("i"), date("s"), date("m") , date("d"), date("Y"))); $nineam = date('Y-m-d 09:00:00'); $nine30 = date('Y-m-d 09:30:00'); $ninepm = date('Y-m-d 18:00:00'); echo '9pm yesterday: '.$nineyesterday; echo '<br/>'; echo '9am: '.$nineam; echo '<br/>'; echo '9pm: '.$ninepm; echo '<br/>'; echo 'now: '.$now; echo '<br/>'; if ((strtotime($now) > strtotime($nineyesterday)) and (strtotime($now) <= strtotime($nineam))) { //count the answers by yes or no echo 'am'; } elseif ((strtotime($now) > strtotime($nineam)) and (strtotime($now) <= strtotime($ninepm))) { //count the answers by yes or no echo 'pm'; } else { echo 'error'; } ?> Thanks in advance hy every one i have two files one is index.php and second insert.php as follow, index.php Code: [Select] <html> <body> <form action="insert.php" method="post"> Time <input type="text" name="time" /> <input type="submit" /> </form> <?php $ctime = date('h:i:s A'); echo "Current time is : " . $ctime ; echo "<br>"; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("time", $con); $result = mysql_query("SELECT * FROM time"); while($row = mysql_fetch_array($result)) { echo date('h:i:s A', strtotime($row['time'])); echo "<br />"; } mysql_close($con); ?> </body> </html> here is my insert.php file code, Code: [Select] <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("time", $con); $sql="INSERT INTO time (time ) VALUES ('$_POST[time]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; echo "<br>"; echo "<a href='index.php'>Home</a>"; mysql_close($con) ?> this code work fine but the form which submit the value of time in database whos code is in index.php file above, i have to enter time in the form text field like this 17:00 and it save the value in database but, i want to enter time in the form text field like this 05:00 PM which automatically save the value in database as 17:00 what should i do with the code help me please thanks hi, i am working on an assignment in which i am getting current date and then getting date of two previous months i.e 2010-09 2010-08 2010-07 the problem is that the code is working perfectly on localhost but when i upload the file it only shows the current date and do not subtract and display dates. can some body guide me that what is the problem and how to solve it. here is the code $date1= date("Y-m"); $date2 = strtotime ( '-1 month' , strtotime ( $date1 ) ) ; $date2 = date ( 'Y-m' , $date2 ); $date3 = strtotime('-1 month', strtotime( $date2 ) ); $date3 = date( 'Y-m' , $date3); ?> <select name=""> <option><?php echo $date1; ?></option> <option><?php echo $date2; ?></option> <option><?php echo $date3; ?></option> </select> Hi, I have a date string being output from a database into a variable $date which looks like: Code: [Select] $date = "2010-09-30 12:45:52"; I'm trying to change the format to: 30 September 2010 (I want to get rid of the time also) Does anyone know how I could do this in PHP? Any help would be much appreciated! Hi, Im having some troubles with a date picker on a form. It enters the date into the date field like this : 21 Sep 2011 I want to be able to insert it into a date field in the mysql database but it just enters it as 0000-00-00 Any ideas ? Many thanks, Scott. Hi All, I am trying to pull a record from my table using the date of birth column (which is a date column) like so.. Code: [Select] $birthday = ('1936-08-21'); $query = "Select * from my_table where dob = $birthday"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ echo "Name is - " .$row['name']; } I know there is a record in the table with a date of birth(dob) value of 1936-08-21 but it does not return any records ? thanks for looking, Tony Hi, I've done a search and cant find anything related to my problem. I have a newsfeed on my site and i want it to display with the latest news at the top. I have this code: Code: [Select] $get_news = "SELECT title, text, DATE_FORMAT(datetime, '%e %b %Y at %T') AS datetime FROM newsfeed ORDER BY datetime DESC"; This works fine on one of my sites but on another i've just hit a problem. It seems to sort only by the day, not the rest of the date. I made a news post today with date and time of "27 Mar 2011 at 12:54:02" but a post from "28 Jan 2011 at 19:59:52" is above it. Any ideas why this is happening? Thanks, Alex I'm having problems posting date from my MYSQL database. The date in my database is this "2011-01-08 02:53:14" but the it only echo's "01.01.70" Could someone help me figure out why? Here is my code: Code: [Select] <?php $servername='localhost'; $dbusername='root'; $dbpassword=''; $dbname='store'; connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } // Get all the data from the "example" table $result = mysql_query("SELECT * FROM henvendelser WHERE status = 'Ubehandlet' ORDER by id desc ") or die(mysql_error()); echo "<table cellspacing='12px' cellpaddomg='5px' align='center'>"; echo "<tr> <th>ID</th> <th> Opprettet </th> <th>Navn</th> <th>Telefon</th> <th>Emne</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array($result)) { $postTime = $row['date']; $thisTime = time(); $timeDiff = $thisTime-$postTime; if($timeDiff <= 604800) { // Less than 7 days[60*60*24*7] $color = '#D1180A'; } else if($timeDiff > 604800 && $timeDiff <= 1209600) { // Greater than 7 days[60*60*24*7], less than 14 days[60*60*24*14] $color = '#D1B30A'; } else if($timeDiff > 1209600) { // Greater than 14 days[60*60*24*14] $color = '#08C90F'; } echo '<tr style="color: '.$color.';">'; echo '<td>'. $row['id'] .'</td>'; echo '<td>'. date('d.m.y', $postTime) .'</td>'; echo '<td><a href="detaljer.php?view='. $row['id'] .'">'. $row['Navn'] .'</a></td>'; echo '<td>'. $row['Telefon'] .'</td>'; echo '<td>'. $row['Emne'] .'</td>'; echo '</tr>'; } echo '</table>'; ?> I want to users can setup time difference in hours, but I dont know how to solve this. Here is script for localtime: $date_format = 'd.m.Y H:i'; $timezone = new DateTimeZone("Europe/Berlin"); $date = new DateTime(); $date->setTimezone($timezone); echo "<div align='right'> Today is " . $date->format("$date_format") . "</div>"; Now I have $user_time in config and users can change this value (example: +1 hours, -3 hours etc...). Users time settings ($user_time) are saved in database. How to display time based on user_time (ex. $date->format("$date_format") ) to display message like this: Today is 16.09.2010 18 (+$user_time) : 40 |