PHP - Daterange Sorted By Date Put In A Table
Hello,
I have a msql table that has data input every hour of every day, so each date is entered 24 times next to the hour field as seen below the PHP... How do I get the information between a daterange that comes from the datepickers (start and end date) to show values of Power, Volt, and current for each day and hour in a report ? Here is what I have written, but I think the time, or multiple of same dates is stopping it from working... <?php if(isset($_POST['start1']) && isset($_POST['end1'])){ $start = (isset($_POST['start1'])) ? date("Y-m-d",strtotime($_POST['start1'])) : date("Y-m-d"); $end = (isset($_POST['end1'])) ? date("Y-m-d",strtotime($_POST['end1'])) : date("Y-m-d"); $con = mysql_connect('xxxxxx', 'xxxxxx', 'xxxxxxxxxx'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("inverters", $con); $sql = "SELECT * FROM report WHERE date BETWEEN '$start' AND '$end'"; echo "<table border='1'> <tr> <th>Date</th> <th>Hour</th> <th>Power</th> <th>Volt</th> <th>Current</th> </tr>"; $res = mysql_query($sql) or die(__LINE__.' '.$sql.' '.mysql_error()); while($row = mysql_fetch_array($res)){ echo "<tr>"; echo "<td>" . $row['Date'] . "</td>"; echo "<td>" . $row['Time'] . "</td>"; echo "<td>" . $row['Power'] . "</td>"; echo "<td>" . $row['Volt'] . "</td>"; echo "<td>" . $row['Current'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); } ?> The DATE is a DATE, the TIME is TIME, the power,volt, current are FLOAT unit ID | Date | Time | Power | Volts | Current | 1 10/15/2010 21:00:00 0 220 100 1 10/15/2010 22:00:00 0 220 100 1 10/15/2010 23:00:00 0 220 100 1 10/16/2010 00:00:00 0 220 100 1 10/16/2010 01:00:00 0 220 100 1 10/16/2010 02:00:00 0 220 100 1 10/16/2010 03:00:00 0 220 100 1 10/16/2010 04:00:00 0 220 100 1 10/16/2010 05:00:00 245 220 100 1 10/16/2010 06:00:00 360 220 100 1 10/16/2010 07:00:00 596 220 100 1 10/16/2010 08:00:00 1567 220 100 1 10/16/2010 09:00:00 1568 220 100 1 10/16/2010 10:00:00 1598 220 100 1 10/16/2010 11:00:00 1642 220 100 1 10/16/2010 12:00:00 1658 220 100 1 10/16/2010 13:00:00 1664 220 100 1 10/16/2010 14:00:00 1598 220 100 1 10/16/2010 15:00:00 1527 220 100 1 10/16/2010 16:00:00 980 220 100 1 10/16/2010 17:00:00 410 220 100 1 10/16/2010 18:00:00 208 220 100 1 10/16/2010 19:00:00 0 220 100 1 10/16/2010 20:00:00 0 220 100 1 10/16/2010 21:00:00 0 220 100 1 10/16/2010 22:00:00 0 220 100 1 10/16/2010 23:00:00 0 220 100 1 10/17/2010 00:00:00 0 220 100 1 10/17/2010 01:00:00 0 220 100 1 10/17/2010 02:00:00 0 220 100 Similar TutorialsI am trying create a webpage that will automatically display new agendas as I add them to the server. I do this right now but I have to put the agendas in the agendas and the board folders. I want to simplify this by only putting the agendas in the board folder. My code kinda works but the results aren't sorted correctly. My code scans the current directory for the list of current boards. The arrary_diff removes the boards that are no longer active. It then appends the current year to the folder information. Next I glob all of the Agendas in the various directories and then I sort the resulting glob. Finally I print the results which are out of date order. I tried sort(basename($agendas)) but that is not valid syntax for sort. Then I was thinking of a 2 dimension array, the first element is the filename, the second element is the fullpath. Then I sort on the first element but I haven't figured out how to get that to work. So I went back to my first code and I am asking what did I do wrong? Am I on the right track to do what I want? The directory structure is like this: Array ( [0] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/01-17-2021_Board_of_Zoning_Appeals_Agenda.pdf [1] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/02-24-2021_Board_of_Zoning_Appeals_Agenda.pdf [2] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/03-17-2021_Board_of_Zoning_Appeals_Agenda.pdf [3] => ./meeting-minutes-agendas/Board_of_Zoning_Appeals/2021/04-21-2021_Board_of_Zoning_Appeals_Agenda.pdf [4] => ./meeting-minutes-agendas/Economic_Development_Committee/2021/01-24-2021_EDC_Agenda.pdf [5] => ./meeting-minutes-agendas/Economic_Development_Committee/2021/02-21-2021_EDC_Agenda.pdf [6] => ./meeting-minutes-agendas/Economic_Development_Committee/2021/03-21-2021_EDC_Agenda.pdf [7] => ./meeting-minutes-agendas/Park_Board/2021/01-21-2021_Park_Board_Agenda.pdf [8] => ./meeting-minutes-agendas/Park_Board/2021/02-18-2021_Park_Board_Agenda.pdf [9] => ./meeting-minutes-agendas/Park_Board/2021/03-18-2021_Park_Board_Agenda.pdf [10] => ./meeting-minutes-agendas/Park_Board/2021/03-27-2021_Park_Board_Agenda.pdf [11] => ./meeting-minutes-agendas/Park_Board/2021/04-22-2021_Park_Board_Agenda.pdf [12] => ./meeting-minutes-agendas/Plan_Commission/2021/01-07-2021_Plan_Commission_Agenda.pdf [13] => ./meeting-minutes-agendas/Plan_Commission/2021/01-21-2021_Plan_Commission_Agenda.pdf [14] => ./meeting-minutes-agendas/Plan_Commission/2021/02-04-2021_Plan_Commission_Agenda.pdf [15] => ./meeting-minutes-agendas/Plan_Commission/2021/02-18-2021_Plan_Commission_Agenda.pdf [16] => ./meeting-minutes-agendas/Plan_Commission/2021/03-04-2021_Plan_Commission_Agenda.pdf [17] => ./meeting-minutes-agendas/Plan_Commission/2021/03-18-2021_Plan_Commission_Agenda.pdf [18] => ./meeting-minutes-agendas/Plan_Commission/2021/04-08-2021_Plan_Commission_Agenda.pdf [19] => ./meeting-minutes-agendas/Plan_Commission/2021/04-22-2021_Plan_Commission_Agenda.pdf [20] => ./meeting-minutes-agendas/Redevelopment_Commission/2021/01-17-2021_RDC_Agenda.pdf [21] => ./meeting-minutes-agendas/Redevelopment_Commission/2021/02-14-2021_RDC_Agenda.pdf [22] => ./meeting-minutes-agendas/Redevelopment_Commission/2021/03-14-2021_RDC_Agenda.pdf [23] => ./meeting-minutes-agendas/Safety_Board/2021/01-08-2021_Safety_Board_Agenda.pdf [24] => ./meeting-minutes-agendas/Safety_Board/2021/02-16-2021_Safety_Board_Agenda.pdf [25] => ./meeting-minutes-agendas/Safety_Board/2021/03-16-2021_Safety_Board_Agenda.pdf [26] => ./meeting-minutes-agendas/Safety_Board/2021/04-22-2021_Safety_Board_Agenda.pdf [27] => ./meeting-minutes-agendas/Sanitary_District/2021/01-19-2021_Sanitary_District_Agenda.pdf [28] => ./meeting-minutes-agendas/Sanitary_District/2021/02-16-2021_Sanitary_District_Agenda.pdf [29] => ./meeting-minutes-agendas/Sanitary_District/2021/03-16-2021_Sanitary_District_Agenda.pdf [30] => ./meeting-minutes-agendas/Sanitary_District/2021/03-23-2021_Sanitary_District_Agenda.pdf [31] => ./meeting-minutes-agendas/Sanitary_District/2021/03-31-2021_Sanitary_District_Agenda.pdf [32] => ./meeting-minutes-agendas/Sanitary_District/2021/04-20-2021_Sanitary_District_Agenda.pdf [33] => ./meeting-minutes-agendas/Town_Council/2021/01-13-2021_Town_Council_Agenda.pdf [34] => ./meeting-minutes-agendas/Town_Council/2021/01-27-2021_Town_Council_Agenda.pdf [35] => ./meeting-minutes-agendas/Town_Council/2021/02-02-2021_Town_Council_Agenda.pdf [36] => ./meeting-minutes-agendas/Town_Council/2021/02-24-2021_Town_Council_Agenda.pdf [37] => ./meeting-minutes-agendas/Town_Council/2021/03-03-2021_Town_Council_Agenda.pdf [38] => ./meeting-minutes-agendas/Town_Council/2021/03-24-2021_Town_Council_Agenda.pdf [39] => ./meeting-minutes-agendas/Town_Council/2021/04-14-2021_Town_Council_Special_Meeting_Agenda.pdf [40] => ./meeting-minutes-agendas/Town_Council/2021/04-14-2021_Town_Council_Study_Session_Agenda.pdf [41] => ./meeting-minutes-agendas/Waterworks_Board/2021/01-07-2021_Waterwork_Board_Agenda.pdf [42] => ./meeting-minutes-agendas/Waterworks_Board/2021/01-19-2021_Waterworks_Board_Agenda.pdf [43] => ./meeting-minutes-agendas/Waterworks_Board/2021/01-28-2021_Waterworks_Board_Agenda.pdf [44] => ./meeting-minutes-agendas/Waterworks_Board/2021/02-16-2021_Waterworks_Board_Agenda.pdf [45] => ./meeting-minutes-agendas/Waterworks_Board/2021/03-16-2021_Waterworks_Board_Agenda.pdf [46] => ./meeting-minutes-agendas/Waterworks_Board/2021/04-20-2021_Waterworks_Board_Agenda.pdf ) What I get is
04-21-2021_Board_of_Zoning_Appeals_Agenda.pdf when it should be:
04-20-2021_Sanitary_District_Agenda.pdf <?php $files = array_diff(scandir('./meeting-minutes-agendas'), array('..', '.', 'Default.php', 'Agendas', 'Police_Commission', 'Utility_Board')); sort($files); foreach($files as &$file) { $file = $file . "/" . date("Y"); } unset($file); $agendas = array(); foreach($files as $file) { $temp = glob('./meeting-minutes-agendas/'. $file . "/*Agenda.pdf"); $agendas = array_merge($agendas, $temp); } unset($files); unset($temp); sort($file); foreach($agendas as $file) { $filedate = str_replace('-', '/',substr(basename($file),0,10)); if (strtotime($filedate) >= strtotime(date('m/d/Y'))) { echo "<a href='"; echo $file; echo "'>"; $file = str_replace('.php', '', $file); echo basename($file); echo "</a><br>\n"; } } unset($file); ?>
I have a table with two columns. The first is an id column, set to be my primary key, non null, unique, int, and auto increment. The second is a varchar(10) column. Very strangely, when I set the varchar(10) column to unique, and try to edit the table in workbench, the table is automatically ordered by my varchar column, and not my id (primary key column). If I mark the varchar(10) column as not unique, data is ordered by the primary key, as expected. What is going on here? I expected the primary key to be default ordering for the table. I hope to not use an ORDER BY clause.
Edited by E_Leeder, 29 November 2014 - 02:14 AM. Hello, I have 2 jquery date pickers (start and end date) to pull the daterange mysql data,that will POST data on the webpage from mysql table. I can not seem to get the PHP to work right. The table is very simple. Unit ID | DATE | Time | Power | Volt | Current| Data is entered every hour (24 hours a day) The jquery date pickers select the date range on the website to post the report.php, and I wish to display the Date,Time,Power,Volt,Current in that range in a straight table on the wen page. You can see the how I want it on the website http://www.pvmonitor.000a.biz/sw-report.php This will help you understand my meaning better. Here is the report.php... Please let me know where I am going wrong. <? $start = (isset($_POST['start'])) ? date("Y-m-d",strtotime($_POST['start'])) : date("Y-m-d"); $end = (isset($_POST['end'])) ? date("Y-m-d",strtotime($_POST['end'])) : date("Y-m-d"); $con = mysql_connect('localhost', 'root', 'XXXXXX'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("inverters", $con); $sql='select * FROM feed AS genreport ' .'BETWEEN [start] and [end]'; $res = mysql_query($sql); while ($row = mysql_fetch_assoc($res)) echo $row['genreport']; echo "<table border='1'> <tr> <th>Date</th> <th>Hour</th> <th>Power</th> <th>Volt</th> <th>Current</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Date'] . "</td>"; echo "<td>" . $row['Time'] . "</td>"; echo "<td>" . $row['Power'] . "</td>"; echo "<td>" . $row['Volt'] . "</td>"; echo "<td>" . $row['Current'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Thanks, Alan Hi, I have switched to a unix server from a windows one and my dir.php now displays in date order which makes things very hard to find Below is the code I use, can anyone tell me what to put, and where ? to make it sort by file name, or point me to a freeware script that has already invented the wheel so to speak. <?php function humansize($size) { $kb = 1024; // Kilobyte $mb = 1024 * $kb; // Megabyte $gb = 1024 * $mb; // Gigabyte $tb = 1024 * $gb; // Terabyte if($size < $kb) return $size."B"; else if($size < $mb) return round($size/$kb,0)."KB"; else if($size < $gb) return round($size/$mb,0)."MB"; else if($size < $tb) return round($size/$gb,0)."GB"; else return round($size/$tb,2)."TB"; } $path= dirname($_SERVER['SCRIPT_FILENAME']); ?> <h3>Files in <?php print $path; ?>:</h3> <ul> <?php $d = dir($path); $icon = ''; while (false !== ($entry = $d->read())) { if ( substr($entry, 0, 1)=='.' ) continue; $size = filesize($path.'/'.$entry); $humansize = humansize($size); $dotpos = strrpos($entry, '.'); if ($dotpos) { $ext = substr($entry, $dotpos+1); if ($ext === 'jpeg' || $ext === 'gif' || $ext === 'png') { $icon = "<img src='$entry' style='width: 48px; height: auto; vertical-align: text-top;' alt='icon' title='$entry' />"; } } print "<li><a href='$entry'>$entry</a> ($humansize) $icon</li>\n"; $icon= ''; } $d->close(); ?> Please help an old fellow who should know better Regards Topshed i've been able to load up a csv file and display it as a html table but what i'm having trouble with is sorting it out with headings a to z but what i am trying to do is have 4 columns like this. Surgestions about how to do what im after i was hoping i could span the say A across all columns and centering them in the future also but thats not really the problem mainly the getting the array of the csv file and code right iguess. any help would be appreciated Code: [Select] <table> <tr> <th>A</th> </tr> <tr> <td>Apple1</td> <td>Apple2</td> <td>Apple3</td> <td>Apple4</td> <td>Apple5</td> <td>Apple6</td> </tr> <tr> <th>B</th> </tr> <td>Banana1</td> <td>Banana2</td> <td>Banana3</td> <td>Banana4</td> <td>Banana5</td> <td>Banana6</td> <tr> <th>C</th> </tr> <td>Cold1</td> <td>Cold2</td> <td>Cold3</td> <td>Cold4</td> <td>Cold5</td> <td>Cold6</td> </table> This is the code for inputting of the csv file i also have some other code i was wanting to use for the sorting of the array data from the csv file i'll past below.... Quote <?php $file = "widgets.csv"; $delimiter = ","; $enclosure = '"'; $column = array("", "", "", ""); @$fp = fopen($file, "r") or die("Could not open file for reading"); while (!feof($fp)) { $tmpstr = fgets($fp, 100); $line[] = preg_replace("/r/", "", $tmpstr); } for ($i=0; $i < count($line); $i++) { $line[$i] = explode($delimiter, $line[$i]); } ?> <html> <head> <title>Albert's Delimited Text to HTML Table Converter</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> </head> <body> <table border="1" cellpadding="5" cellspacing="0"> <tr> <?php for ($i=0; $i<count($column); $i++) echo "<th>".$column[$i]."</th>"; ?> </tr> <?php for ($i=0; $i < count($line); $i++) { echo "<tr>"; for ($j=0; $j < count($line[$i]); $j++) { echo "<td>".$line[$i][$j]."</td>"; } echo "</tr>"; } fclose($fp); ?> </table> </body> </html> Heres the code for the sorting of the table data from the array Quote <?php echo "QUERY_STRING is ".$_SERVER['QUERY_STRING']."<p>"; $rev=1; $sortby=0; if(isset($_GET['sortby']))$sortby = $_GET['sortby']; if(isset($_GET['rev']))$rev = $_GET['rev']; //Open and read CSV file example has four columns $i=-1; $ff=fopen('widgets2.csv','r') or die("Can't open file"); while(!feof($ff)){ $i++; $Data[$i]=fgetcsv($ff,1024); } //Make columns sortable for each sortable column foreach ($Data as $key => $row) { $One[$key] = $row[0]; // could be $row['Colname'] $Two[$key] = $row[1]; //numeric example $Three[$key] = $row[2]; $Four[$key] = $row[3];} //numeric example //Case Statements for Sorting switch ($sortby){ case "0": if($rev=="1")array_multisort($One, SORT_NUMERIC, $Data); //SORT_NUMERIC optional else array_multisort($One, SORT_NUMERIC, SORT_DESC,$Data); $rev=$rev*-1; break; case "1": if($rev=="1")array_multisort($Two, $Data); else array_multisort($Two, SORT_DESC, $Data); $rev=$rev*-1; break; case "2": if($rev=="1")array_multisort($Three, SORT_NUMERIC, $Data); else array_multisort($Three, SORT_NUMERIC, SORT_DESC,$Data); $rev=$rev*-1; break; case "3": if($rev=="1")array_multisort($Four, $Data); else array_multisort($Four, SORT_DESC, $Data); $rev=$rev*-1; break;} echo ("<table border=2>"); //$rev is reverse variable echo ("<th><a href=\"SortTable.php?sortby=0&rev=$rev\" title=\"Click to Sort/Reverse sort\">One</a></th>"); echo ("<th><a href=\"SortTable.php?sortby=1&rev=$rev\" title=\"Click to Sort/Reverse sort\">Two</a></th>"); echo ("<th><a href=\"SortTable.php?sortby=2&rev=$rev\" title=\"Click to Sort/Reverse sort\">Three</a></th>"); echo ("<th><a href=\"SortTable.php?sortby=3&rev=$rev\" title=\"Click to Sort/Reverse sort\">Four</a></th>"); $i=0; foreach($Data as $NewDat){ if($NewDat[0]!=""){ //error trap $str="<tr>"; foreach($NewDat as $field)$str.="<td>$field</td>"; $str.="</td>\n"; echo $str;}} fclose($ff); echo "</table>"; Hey, I am grabbing a date from a row in my table which is currently formatted as: date("Y-m-d") 2010-09-29 So in my code I have something like this: $row['date']; How do I use this to rearrange the date to look like: 09-29-2010 I looked at the formatting tutorials, but they explain how to format it for the date you are currently setting into a variable. Hi all - I am parsing info from mysql into a php table but the date being returned is in YYYY-MM-DD format and I want it DD-MM-YYYY. How would I do this? Code at the moment is: Code: [Select] $link = connect(); function get_user_posts(){ $getPosts = mysql_query('SELECT a.id as id,a.post as question, a.answer as answer, a.created as created, a.updated as updated, b.vclogin as admin FROM user_posts as a, admin as b WHERE a.admin_id=b.adminid',connect()); return $getPosts; } Code: [Select] <table class="list"> <tr> <th><?php echo getlocal("upost.post") ?></th> <th><?php echo getlocal("upost.answer") ?></th> <th><?php echo getlocal("upost.admin") ?></th> <th><?php echo getlocal("upost.created") ?></th> <th><?php echo getlocal("upost.updated") ?></th> <th></th> <th></th> </tr> <?php $all_questions = get_user_posts(); while ($question = mysql_fetch_assoc($all_posts)): ?> <tr> <td><?php echo $post['post']?></td> <td><?php echo $post['answer']?></td> <td><?php echo $post['admin']?></td> <td><?php echo $post['created']?></td> <td><?php echo $post['updated']?></td> <td><a href="javascript:user_post('<?php echo $post['id']?>')">edit</a></td> <td><a href="javascript:delete_post('<?php echo $post['id']?>')">delete</a></td> </tr> THANKS! Hi there, i'm trying to sum up values from mysql based on their date, specifically only values from entries with the same date should be added together, my db looks like this: id, codes, value, date now i'm building a statistics page, the value field is always 50, for showing the total for all the entries i'm just doing Code: [Select] $totalincome = $codes * 50; and print that on the statistic, i want to have statistics for each day, the date is saved in this format: YYYY-MM-DD how could i do that ? Thanks ! 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 Here is one part of php code. Here I try to show in last 1 month which dates exactly user made orders. When I run the SQL code in command prompt it works. I think problem is in while loop. Thanks beforhand for contribution. $query = "SELECT Date FROM orders WHERE User='$username' and DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= Date;"; $result = mysql_query($query,$link_id) or die (mysql_error()); echo "<table border='1'> <tr> <td> Last 1 month's orders:</td> </tr>"; while($order_date = mysql_fetch_row($result)) { echo "<tr>"; echo "<td>" . $order_date[0] . "</td>"; echo "</tr>"; } echo "</table> I have a simple mysql database holding information about an image upload including its 'name' and 'date uploaded' [current_timestamp()] to a folder 'image' I then display it into a table using the php ‘foreach’ facility. I want the date to be displayed in the ‘dd/mm/yyyy’ format. not the default yyyy/mm/dd. Here is the relevant code <?php $conn = mysqli_connect("localhost", "root", "", "dbname"); $results = mysqli_query($conn, "SELECT * FROM tablename"); $image = mysqli_fetch_all($results, MYSQLI_ASSOC); ?> <?php foreach ($image as $user): ?> <td><p>NAME</p><?php echo $user['name']; ?></td> <td><p>COMMENT</p><?php echo $user['comment']; ?></td> <td><p>DATE</p><?php echo $user['date']; ?></td> What do I need to do? THANKS- Warren Hey all, Im currently working on a site which I save a cookie on users computer for 1 month as well a row in a table with the 1 month expiring date plus cookie id. What I would like to know is if theres a way to make the server check the table every day at say 12pm to see if any corresponding user cookies in each row have expired on that day as to remove them from the table to match the expiring cookie on the users computer? I would like not to have to rely on a user/admin accessing in to make a script run instead have something thats timed to go off automatically instead? Is there anyway of doing this? Thanks! This is my first real jump into PHP, I created a small script a few years ago but have not touched it since (or any other programming for that matter), so I'm not sure how to start this. I need a script that I can run once a day through cron and take the date from one table/filed and insert it into a different table/field, converting the human readable date to a Unix date. Table Name: Ads Field: endtime_value (human readable date) to Table Name: Node Field: auto_expire (Converted to Unix time) Both use a field named "nid" as the key field, so the fields should match each nid field from one table to the next. Following a tutorial I have been able to insert into a field certain data, but I don't know how to do it so the nid's match and how to convert the human readable date to Unix time. Thanks in advance!. 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. 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. 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? (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 guys, I'm putting together a small event system where I want the user to add his own date and time into a textfield (I'll probably make this a series of drop-downs/a date picker later). This is then stored as a timestamp - "0000-00-00 00:00:00" which displays fine until I try to echo it out as a UK date in this format - jS F Y, which just gives today's date but not the inputted date. Here's the code I have right now: Code: [Select] $result = mysql_query("SELECT * FROM stuff.events ORDER BY eventdate ASC"); echo "<br />"; echo mysql_result($result, $i, 'eventvenue'); echo ", "; $dt = new DateTime($eventdate); echo $dt->format("jS F Y"); In my mysql table eventdate is set up as follows: field - eventdate type - timestamp length/values - blank default - current_timestamp collation - blank attributes - on update CURRENT_TIMESTAMP null - blank auto_increment - blank Any help as to why this could be happening would be much appreciated, thanks. |