PHP - Date Formating
I'm trying to figure out how to format a variable. I am listing the contents of a directory from an array and I trying to format the date field to be like - Jan 07, 2011 01:35 PM. When I try this format I get a 500 error message.
<td width="'.$width_of_dates_column.'">'.$files("M d Y h:i:s A", filemtime['date'])[$key].'</td></tr>'; Is is possible to format the date after it's been put into the array or does it have to be done while it's being processed. Not sure if you need more code to determine the formatting. Please let me know if you do. Thank you. Similar TutorialsI'm using system() to run NMAP and then display the output but it's one big string, how can I format it to look like what I see in the command line? web app output: Starting Nmap 5.00 ( http://nmap.org ) at 2012-03-21 18:44 CDT Interesting ports on localhost (127.0.0.1): Not shown: 993 closed ports PORT STATE SERVICE 80/tcp open http 111/tcp open rpcbind 139/tcp open netbios-ssn 443/tcp open https 445/tcp open microsoft-ds 631/tcp open ipp 3306/tcp open mysql Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds 0 command line output: Starting Nmap 5.00 ( http://nmap.org ) at 2012-03-21 18:48 CDT Interesting ports on localhost (127.0.0.1): Not shown: 993 closed ports PORT STATE SERVICE 80/tcp open http 111/tcp open rpcbind 139/tcp open netbios-ssn 443/tcp open https 445/tcp open microsoft-ds 631/tcp open ipp 3306/tcp open mysql Nmap done: 1 IP address (1 host up) scanned in 0.45 seconds Code: [Select] <?php // path to NMAP $Path = '/usr/bin/nmap'; if(isset($_POST['scan'])) { $IP = $_POST['IP']; $ScanType = $_POST['ScanType']; echo "<br /><u>Results for NMAP Scan</u> <br />"; system("$Path $ScanType $IP 2>&1", $Output); echo $Output; } ?> any help would be greatly appreciated, thanks in advance!! Hi! I'm working a on wordpress website with member pages. Members enter their information via custom fields. Everything is working great except when trying to create a link based on one of those custom field. Unless the member enter his website address in the http://mysite.com format the link my code create is not valid. This is the code i'm currently using Code: [Select] <?php $msite = get_post_meta($post->ID, 'ccio_site', true) ; if (!empty($msite)) { ?><li>Site Internet: <a href="<?php echo ($msite) ; ?>"><?php echo ($msite) ; ?></a></li><?php } ?> Example of a member page where the format create an error. The input field is: Code: [Select] www.pechabot.com Example of a member page where the format is ok. The input field is Code: [Select] http://www.annuairesgb.com How can I format the input string so my code will work even if someone doesn't write the full address with the http:? Thanks a lot for looking So basically I have text which appears on an image. Code: [Select] $ability = "$title gets ability"; //Create Ability imagettfbbox(30, 0, $font, $ability); imagettftext($image, 30, 0, 70, 700, $fontcolor, $font, stripslashes($ability)); But the line of text is longer than the width of the area on the image it needs to fit in. How can I change this so it automatically starts a new line once it reaches the end of said area? Looking for ideas and advise on this one. I want to take a 10 digit number and 1234567890 and format it like 132-456-7890 what would be my best bet as choice of methods to do this? Hi Folks, I understand the basic math to accomplish what I want, at least I think I do I would like to confirm my logic and I need help with the final output format. I am coding a simple browser based, resource type of game. The gamer will select a certain item to produce another item and it will take x time to do it. Here is the basics of what I want, minus the coding to make it look pretty. How do I format $y to show HHH:MM:SS? Code: [Select] $complete = time() + $x; // To show how much time is remaining until completion or complete $y = $complete - time(); if $y > 0 { echo $y; } else { echo "complete"; } Hi All, not able to understand I'm making miskate in CSS or PHP foreach statement. Need help with proper formating of the below code. I want to format the so that seasons divs will contain all the details about the episodes, title & plot. As of now season div is only wraping around the first episode only & ignoring remaining episodes details. Sorry I'm not able to explain this in words but if you access below code you will be able to understand. Code: [Select] <html> <head> <style type="text/css"> .main { width: 750px; margin-right: auto; margin-left: auto; background: #cc1; clear: both; overflow:auto; } .season { margin: 5px; padding: 5px; width: 730px; background: #960; } .details { overflow:hidden; } .ep, .title, .airdate, .plot { margin: 5px; padding: 5px; width: 675px; background: #CCC; } </style> </head> <body> <?php $eps = array( array( 'year' => '2005', 'eptitle' => 'title1', 'airdate' => 'Apr 24 2009', 'epplot' => 'plot of S01E01', 'season' => '1', 'episode' => '1'), array( 'year' => '2005', 'eptitle' => 'title2', 'airdate' => 'May 1 2009', 'epplot' => 'plot of S01E02', 'season' => '1', 'episode' => '2'), array( 'year' => '2005', 'eptitle' => 'title3', 'airdate' => 'May 8 2009', 'epplot' => 'plot of S02E01', 'season' => '2', 'episode' => '1'), array( 'year' => '2005', 'eptitle' => 'title4', 'airdate' => 'May 12 2009', 'epplot' => 'plot of S02E02', 'season' => '2', 'episode' => '2'), array( 'year' => '2005', 'eptitle' => 'title5', 'airdate' => 'May 15 2009', 'epplot' => 'plot of S03E01', 'season' => '3', 'episode' => '1'), array( 'year' => '2005', 'eptitle' => 'title6', 'airdate' => 'May 28 2009', 'epplot' => 'plot of S03E02', 'season' => '3', 'episode' => '2'), ); //var_dump($eps); $season = 0; echo "<div class='main'>"; foreach($eps as $k){ // season check start if($season!=$k['season']) { echo "<div class='season'><b>SEASON : </b>".$k['season']; } //season check finish echo "<div class='details'>"; echo "<div class='ep'><b>EPISODE : </b>".$k['episode']."</div>"; echo "<div class='title'><b>TITLE : </b>".$k['eptitle']."</div>"; echo "<div class='airdate'><b>AIRDATE : </b>".$k['airdate']."</div>"; echo "<div class='plot'><b>PLOT : </b>".$k['epplot']."</div>"; echo "</div>"; // season check start if($season!=$k['season']) { echo "</div>"; $season = $k['season']; } } echo "</div>"; ?> </body> </html> I have created an email template for HTML emails, but something isn't quite right. I use roundcube for my webmail and the email shows up perfect, but then in outlook it looks terrible. Gmail wont even receive it and in godaddy's webmail it is displayed at text with the <table> code written out. Any idea what I am missing? // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: <[mail]>' . "\r\n"; $headers .= 'From: cjkjckjxc <noreply@cojch.com>' . "\r\n"; $body = <<<BODY //stuff goes here BODY; Hello i would like to as a little help on how to proper format an foreach output into an HTML table. I have a small function inside an class, that will retrieve the data of an MySQL table and return the result in 1 array, Outside that function i can get the values displayed i only need to format it to show in an table here's what i have: function that gets the data Code: [Select] function getfansub(){ $subfanarray = array(); $query = mysql_query("SELECT * FROM anr_fansub WHERE 1"); while($result = mysql_fetch_array($query)){ $subfanarray[] = $result; } return $subfanarray; } Outside the funtion/class Code: [Select] $fansubarray = $mysql->getfansub(); VAR_DUMP( $fansubarray ); echo "<br><br>"; foreach($fansubarray as $name){ echo $name['FansubID'] ." ". $name['Designation'] ." ". $name['Website'] ." ". $name['tracker'] ." ". $name['irc'] ."<br>"; } The problem i have with the formating (i really dont know who i can do it) is when he reaches the IRC link he needs to open and close the td and tr brakets of the table. any help or tip is apreciated, thanks in advance how to format only one specific row based on the value of one cell in a row? $result = mysql_query(select bal, etc. etc ..query ) while($row = mysql_fetch_assoc($result)) echo "<tr>"; echo "<td>" . $row['Account'] . "</td>"; echo "<td>" . $row['licence'] . "</td>"; echo "<td>" . $row['own'] . "</td>"; echo "<td>" . $row['bal'] . "</td>"; echo "</tr>"; Would appreciate help on how to format only the $row['bal'] output to red colour IF bal >5000 Thanks Hey guys & gals, i have the following code: Code: [Select] <?php $date= $_SESSION['date']; echo $date; ?> Which is an echo of an earlier page: Code: [Select] <?php $_SESSION['date'] = date("c")?>; How do i format the echo of the first quote code? At present it echo's like so... Quote 2011-03-30T15:43:43+01:00 ...which although is useful for back office purposes, not so easy on the eye for the customer. How can i format so it's like DATE-MONTH-YEAR? I have googled this and there are examples, but none for when echoing a $_SESSION which is where i'm falling flat on my face. I tried this: but it doesn't work :-( Code: [Select] echo $startdate ("F j, Y") Thanks in advance to all who read and reply 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 How to output a MySQL timestamp field to correct local time with daylight saving with PHP?
Local time is set in php.ini with: date.timezone = "Europe/London"
Confirmed set with: <?php echo date_default_timezone_get(); ?>
But when I echo the timestamp field it does not display correct UK time for the record (an hour behind correct UK time).
<?php echo date('jS F Y - g:ia', strtotime($row['Date'])); ?>
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. 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? 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. (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 i have a table that shows payments made but want to the payments only showing from a set date(06/12/14) and before this date i dont want to show
this is my sql that doesnt seem to work and is showing dates before the specified date.
.
"SELECT * FROM payments2014, signup2014, editprop2014 WHERE signup2014.userid = payments2014.payment_userid AND editprop2014.prop_id = signup2014.prop_id AND signup2014.userid !='page1' AND signup2014.userid !='page6' AND signup2014.userid !='page4' AND payments2014.payment_transaction_status !='none' AND payments2014.payment_transaction_status !='CANCELLEDa' AND payments2014.payment_type !='deposit' AND payments2014.payment_paid_timestamp NOT LIKE '%2012%' AND payments2014.payment_paid_timestamp NOT LIKE '%2011%' AND payments2014.payment_paid_timestamp >= '06/12/14' ORDER BY payments2014.payment_id DESC"i have some other parts in the statment but this one that should be filtering is host_payments2014.payment_paid_timestamp >= '06/12/14'thanks in advance Hi, Currently I am making a module for joomla. every article has an publish date, if the article was published in 7 days ago, it will displayed as "article in last week", My idea is to use today's date - publish date, if the result is greater than 7 and smaller than 14, the article will be displayed as "article in last week. Any one know how to write this code? Here is what I have got, but not working. <?php $todays_date = date("Y-m-d"); $result = mysql_query("select * from jos_content where $test between $todays_date-14 and $todays_date-7"); while($row = mysql_fetch_array($result)) { echo "$todays_date - $row[title]"; } ?> |