PHP - Formatting Output Date
Hi all
I have a PHP script with the following var print $date; at the moment it is formatting the date like 03-24-2010 is it possible to get PHP to switch the date and month, so it looks like 24-03-2010 Thanks Similar TutorialsHi 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. Hi, I am trying to print my database records into a php page. I am able to succesfully print the values however the values are being duplicated. For example If I have two records in the employee_details, every these two records are being printed twice on my php page. can anyone tell me the reason why? The output that I see is as follows 7 7 3a7cf5162a9c0a5014c92021e7ca0bf0 3a7cf5162a9c0a5014c92021e7ca0bf0 Bryan Bryan 4111 4111 Admin Admin 6 6 6743c3d1519ab4f2cd9a78ab09a511bd 6743c3d1519ab4f2cd9a78ab09a511bd Raul Raul 601 W Yandell Dr, 601 W Yandell Dr, Admin Admin <html> <head> </head> <body> <?php mysql_connect("localhost","root",""); mysql_select_db("encryption") or die(mysql_error()); $query = mysql_query("select * from employee_details"); ?> <table> <?php for($counter = 0;$row=mysql_fetch_array($query); $counter++) { print ("<tr>"); foreach($row as $key=> $value) print ("<td>$value</td>"); print ("</tr>"); } ?> </table> </body> </html> Hi, Has anyone come across an issue when saving DOM to a file and Code: [Select] $document->preserveWhiteSpace = false; $document->formatOutout = true; has no effect? Hi, I'm trying to achieve a special output of dates. I essentially have an array of dates like so: // dates in yyyy-mm-dd format $dates = array('2005-05-21', '2006-11-01', '2006-11-02', '2020-09-28', '2020-09-29', '2020-09-30', '2020-10-01'); I need to output theses dates like so: 05 may 2005 01, 02 november 2006 28, 29, 30 september 2020 01 october 2020
I'm really not sure how to go about this. I'm sure this must be possible. Any help would be great!! Thanks a bunch! Pat I have a mysql database that has your typical data in it, ie. name address, etc. The problem I am having is with the address. The address is setup as a varchar with 200 as the length and the data is street, city, st, zip on 1 line. I need to format the output with street on 1 line and city, st, zip on another. I cannot change input format because of the way the program uses the address string to fetch the lat and lng before it writes it to the database. Is there a way to add a line break or <br> to the address before it is written or change it after it is written using sql or php script or possible as I format the output? The street, city, st, zip are separated by commas in the record. Thanks in advance for all the reply's I have this report that I have written and it looks fine on the screen but the printed output is to big for the page and very ugly. How would I reformat it so it prints better.
<html> <head> <title>Load Report</title> </head> <body> <h1>Load Report</h1> <?php $load=$_POST["Load_ID"]; $connect =odbc_connect("removed"); if(!$connect) { exit("Connection Failed: " . $connect); } $sql="SELECT m1_DC.dbo.SalesOrders.UOMPDROPSEQUENCE ,m1_DC.dbo.organizationlocations.cmlPhoneNumber ,m1_DC.dbo.organizationlocations.cmlName ,m1_DC.dbo.organizationlocations.UCMLSTOREHOURSTXT ,m1_DC.dbo.SalesOrders.OMPSHIPPINGMETHODID ,m1_DC.dbo.SalesOrders.UOMPTRUCKNUMBER ,m1_DC.dbo.SalesOrders.ompCustomerPO ,m1_DC.dbo.SalesOrders.UOMPTOTALBOXCOUNT ,m1_DC.dbo.SalesOrders.UOMPVOLUMETOTAL ,m1_DC.dbo.organizationlocations.CMLADDRESSLINE1 ,m1_DC.dbo.organizationlocations.CMLADDRESSLINE2 ,m1_DC.dbo.organizationlocations.CMLCITY ,m1_DC.dbo.organizationlocations.CMLSTATE ,m1_DC.dbo.organizationlocations.CMLPOSTCODE ,m1_DC.dbo.SalesOrders.OMPREQUESTEDSHIPDATE ,m1_DC.dbo.SalesOrders.ompSalesOrderID ,m1_DC.dbo.SalesOrders.ompOrderTotalBase ,convert(varchar(10),m1_DC.dbo.SalesOrders.uompbuilddate,110) as BuildDate FROM m1_DC.dbo.SalesOrders LEFT OUTER JOIN m1_DC.dbo.organizationlocations ON ompshiporganizationid = cmlorganizationid AND ompshiplocationid = cmllocationid WHERE m1_DC.dbo.SalesOrders.UOMPTRUCKNUMBER='$load' Union All SELECT m1_KF.dbo.SalesOrders.UOMPDROPSEQUENCE ,m1_KF.dbo.organizationlocations.cmlPhoneNumber ,m1_KF.dbo.organizationlocations.cmlName ,m1_KF.dbo.organizationlocations.UCMLSTOREHOURSTXT ,m1_KF.dbo.SalesOrders.OMPSHIPPINGMETHODID ,m1_KF.dbo.SalesOrders.UOMPTRUCKNUMBER ,m1_KF.dbo.SalesOrders.ompCustomerPO ,m1_KF.dbo.SalesOrders.UOMPTOTALBOXCOUNT ,m1_KF.dbo.SalesOrders.UOMPVOLUMETOTAL ,m1_KF.dbo.organizationlocations.CMLADDRESSLINE1 ,m1_KF.dbo.organizationlocations.CMLADDRESSLINE2 ,m1_KF.dbo.organizationlocations.CMLCITY ,m1_KF.dbo.organizationlocations.CMLSTATE ,m1_KF.dbo.organizationlocations.CMLPOSTCODE ,m1_KF.dbo.SalesOrders.OMPREQUESTEDSHIPDATE ,m1_KF.dbo.SalesOrders.ompSalesOrderID ,m1_KF.dbo.SalesOrders.ompOrderTotalBase ,convert(varchar(10),m1_KF.dbo.SalesOrders.uompbuilddate,110) FROM m1_KF.dbo.SalesOrders LEFT OUTER JOIN m1_KF.dbo.organizationlocations ON ompshiporganizationid = cmlorganizationid AND ompshiplocationid = cmllocationid WHERE m1_KF.dbo.SalesOrders.UOMPTRUCKNUMBER='$load' order by UOMPDROPSEQUENCE"; $result =odbc_exec($connect,$sql); if(!$result){ exit("Error in SQL"); } $data= ''; while (odbc_fetch_row($result)) { $UOMPDROPSEQUENCE=odbc_result($result,"UOMPDROPSEQUENCE"); $cmlName=odbc_result($result,"cmlName"); $cmlPhoneNumber=odbc_result($result,"cmlPhoneNumber"); $UCMLSTOREHOURSTXT=odbc_result($result,"UCMLSTOREHOURSTXT"); $ompCustomerPO=odbc_result($result,"ompCustomerPO"); $UOMPTOTALBOXCOUNT=odbc_result($result,"UOMPTOTALBOXCOUNT"); $UOMPVOLUMETOTAL=odbc_result($result,"UOMPVOLUMETOTAL"); $CMLADDRESSLINE1=odbc_result($result,"CMLADDRESSLINE1"); $CMLADDRESSLINE2=odbc_result($result,"CMLADDRESSLINE2"); $CMLCITY=odbc_result($result,"CMLCITY"); $CMLSTATE=odbc_result($result,"CMLSTATE"); $CMLPOSTCODE=odbc_result($result,"CMLPOSTCODE"); $ompSalesOrderID=odbc_result($result,"ompSalesOrderID"); $ompOrderTotalBase=odbc_result($result,"ompOrderTotalBase"); $uompbuilddate=odbc_result($result,"BuildDate"); { { if($UOMPDROPSEQUENCE % 2 == 0 ) {$style = '#FFFAFA';} else {$style = '#D3D3D3';}} } $data .= "<tr bgcolor=$style><th>$UOMPDROPSEQUENCE</th>"; $data .= "<th style='text-align:left' height='10'>$cmlName</th>"; $data .= "<td style='text-align:left' height='10'>$UCMLSTOREHOURSTXT</td>"; $data .= "<td style='text-align:center' height='10'>$ompCustomerPO</td>"; $data .= "<td style='text-align:center' height='10'>$UOMPTOTALBOXCOUNT</td>"; $data .= "<td style='text-align:center' height='10'> $UOMPVOLUMETOTAL</td>"; $data .= "<td style='text-align:center' height='10'> $CMLADDRESSLINE1</td>"; $data .= "<td style='text-align:center' height='10'> $CMLADDRESSLINE2</td>"; $data .= "<td style='text-align:center' height='10'> $CMLCITY</td>"; $data .= "<td style='text-align:center' height='10'> $CMLSTATE</td>"; $data .= "<td style='text-align:center' height='10'> $CMLPOSTCODE</td>"; $data .= "<td style='text-align:center' height='10'>$ompSalesOrderID</td>"; $data .= "<td style='text-align:center' height='10'>$ompOrderTotalBase</td>"; //$data .= "<td style='text-align:center'>$uompbuilddate</td>"; $data .= "<td style='text-align:center' height='10'>$cmlPhoneNumber</td></tr>"; } echo "<table><tr>"; echo "<th>Load $load</th><tr>"; echo "<th>Drop</th>"; echo "<th>Name</th>"; echo "<th>Note</th>"; echo "<th>PO</th>"; echo "<th>Box_count</th>"; echo "<th>Cubes</th>"; echo "<th>ADDRESSLINE</th>"; echo "<th>ADDRESS2</th>"; echo "<th>CITY</th>"; echo "<th>STATE</th>"; echo "<th>ZIP</th>"; echo "<th>Order_ID</th>"; echo "<th>Order_Total</th>"; //echo "<th>Build-Date</th>"; echo "<th> Phone </th></tr>"; echo $data; odbc_close($connect); ?> </body> </html> Having used unix timestamps in the past formatting the date used to be easy. But since converting to mysql DATETIME im struggling to format it properly. I basically pull the date from the database, convert it using strtotime(), then convert it to a date using date(). The problem is that when i use 'a' to display am/pm the time almost always says am. If the time is 11am then it will display 11am. If it's 12pm then it will display 12pm, but if it comes to 1pm and above it will revert back to 1am. This is the date string I use: date('jS M Y g:i a'); is this due to the fact that mysql DATETIME uses 24 hour clock ('H'), if so is there a way around this? I'm going round in circles with this one, but I have a feeling that the answer is obvious. I have POST information that I want to use as a date and display it using date format, but I don't know how to The POST data outputs the following: 2011-9-23 Assuming I have defined $date as the posted data from the previous form, how do I write some code to tell it to output it as September 23, 2011, or just Sept 2011? Hi, When I do this the result is a date of zeros? $DateAndTime = date('d-m-y', strtotime($DateAndTime)); All I want is a date in format of DD0MM-YYY and the Time in HH:MM::SS Any help would be great! I know it is basic, Thanks in advance I'm not sure what I'm doing wrong. I have a date in a table which is formatted as: 2010-08-13 00:00:00. I am trying to change the date through PHP to display as 08-13-2010. The date is being formatted as 12-31-1969. Here's my code. if($registrant->StatusDate != '0000-00-00 00:00:00') { $formattedDate = date('m-d-Y', $registrant->StatusDate); $statusDate = ' as of ' . $formattedDate; } Can anyone advise me what I am doing wrong? Thanks! Hi Simple question, how do I reFormat a date. $dateCreated (2012-01-14) to become: 14th jan 2012 So far I have this, but it's not working: Code: [Select] $expDate = explode('-',$dateCreated); $date1 = mktime(0, 0, 0, date('m', $expDate[1]), date('d', $expDate[2]), date('Y', $expDate[0])); $date = date('d m Y', $date1); Thanks To echo this: Posted on: October 23rd 2011 ... I'm querying my db with this: DATE_FORMAT(creation_date, '%M %D %Y') What if I wanted to echo this: 23. Oktober, 2011 ... that is, to display the date as it would be shown in German? TIA if you can help. I have selected datetime values from a MySQL database (originally stored with the NOW() method) and want to present them on a page formatted in a specific way. I succeded in making it work with the following php code:
$time = date('d/m Y H:i', strtotime($row['time'])); echo $time;I am however unsure if this is the best way to do it? I noticed some comments at php.net stating that this method has some limitations due to UNIX time. I am confused. There seem to be many ways of formatting date and time. Maybe somebody can clarify the situation, and tell me what will be appropriate in the current situation? I will appreciate any suggestions ... Erik Edited by erikla, 17 July 2014 - 10:01 AM. 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! Hi Guys, I have got a date string which looks like the following: Quote Thu Feb 09 2012 07:25:00 GMT 0000 (GMT Standard Time) I need to convert it to Quote d-m-Y H:i format. Any ideas on how to do this? Thanks! How would I put today date for instance into mysql_query? I just want the date and have the format be year, month, day. The format in the database looks like 2010-04-05. That being used as an example. And I have three drop down menus, which you can select the year, month, and day, but it doesn't seem to be working. What am I doing wrong? I must admit that dates and timestamps really confuse me! I have a query that gets a field named "date_purchased" and returns it like this "2010-09-05 09:58:12" What I need to do is add one year to the date, and display it like this "September 5, 2011" Basically, it's displaying the end date of a one year subscription. The database captures the purchase date with the order, so I want to grab that, add a year, and display it to the customer. Any help would be most appreciated! Currently the date is stored in the database as 28-02-2011 - 21:00:30 and the variable is: $date['mTime'] How can I format it too look "pretty" like this: February 28, 2011 - 10:00 PM? (don't need the seconds) I have the date stored as: date( "d/m/Y" ) After it's pulled from the database, I would like it to display like: date( "F j, Y" ) I have tried below, but the output makes d the month and m the day. $dateStamp = strtotime($row['startrepeat']); $dateFormatted = date("F j, Y", $dateStamp); Hi all, new to PHP and had a syntax question. I have the following code: print "<p>{$row['comment_createdate']}; This prints out a date from my sqlquery as a database datetime. I need to format it to display "Monday June 15, 2010 5:15 pm". I'm not sure how/where to attach a date() function to the record. (If it matters, the line above is inside of a loop going through several records). This really applies to attaching functions to columns within a recordset in general. Many thanks ahead of time. |