PHP - Formatting A Php Date From String
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! 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 all Been trying to get my head around formatting a string, and struggling. I have a serious of numbers held in a DB and I need these to display as 5 figure numbers. if the DB held the record "48" I would need this to be displayed as "00048". Can anyone give me a clue. I've tried reading the php manual but this just confuses me more. I am having a problem with what is probably encoding. I am pulling strings from a WordPress database. Below is a sample string: Code: [Select] Sed nec neque quis sapien scelerisque aliquet. In in est odio, ac auctor erat. Vestibulum fringilla dapibus sodales. Morbi facilisis egestas arcu, eu semper mi luctus vitae. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse sollicitudin, metus sed hendrerit tristique, enim ante venenatis metus, ac consectetur mauris lorem et felis. Phasellus ac purus massa. Aliquam ligula mauris, iaculis et posuere vitae, pellentesque sit amet leo. Praesent at eros et lacus scelerisque feugiat. Aliquam non facilisis libero. Ut blandit leo ut tortor convallis porttitor. Aliquam erat volutpat. Aliquam rhoncus rutrum metus, tempor sollicitudin ante laoreet in. Sed tincidunt nibh a augue euismod sagittis. Fusce ullamcorper ultricies nisi, sit amet elementum mi scelerisque eget. Cras sed elit ligula, sit amet aliquam lectus. Nulla vel mollis nibh. Pellentesque ultricies, dui non aliquam eleifend, tortor ligula blandit dolor, quis interdum diam augue non eros. Nullam id molestie nunc. Integer id tempus est. When WordPress displays this text, it is formatted correctly, with spaces between paragraphs, etc. When I pull the string from the database, and echo it onto a page, the spaces between paragraphs are replaced by spaces, so in the end the output is as follows: Code: [Select] Sed nec neque quis sapien scelerisque aliquet. In in est odio, ac auctor erat. Vestibulum fringilla dapibus sodales. Morbi facilisis egestas arcu, eu semper mi luctus vitae. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse sollicitudin, metus sed hendrerit tristique, enim ante venenatis metus, ac consectetur mauris lorem et felis. Phasellus ac purus massa. Aliquam ligula mauris, iaculis et posuere vitae, pellentesque sit amet leo. Praesent at eros et lacus scelerisque feugiat. Aliquam non facilisis libero. Ut blandit leo ut tortor convallis porttitor. Aliquam erat volutpat. Aliquam rhoncus rutrum metus, tempor sollicitudin ante laoreet in. Sed tincidunt nibh a augue euismod sagittis. Fusce ullamcorper ultricies nisi, sit amet elementum mi scelerisque eget. Cras sed elit ligula, sit amet aliquam lectus. Nulla vel mollis nibh. Pellentesque ultricies, dui non aliquam eleifend, tortor ligula blandit dolor, quis interdum diam augue non eros. Nullam id molestie nunc. Integer id tempus est. What can I do to follow WordPress' formatting? Hi, I have a textarea called registerDomain which i enter multiple domain names into (separated by a new line) e.g. www.google.com www.sky.com www.bt.comI have the following code to get each of the domains and format them like google.com (lowercase without any spaces) sky.com (lowercase without any spaces) bt.com (lowercase without any spaces)The below code I have works perfectly, however its awful to look at. I wondered if anyone could advise on a cleaner/more elegant way of achieving this. Thanks, if (isset($_POST['submit'])) { $values = trim($_POST['registerDomain']); $array = explode("\n", $values); $array = array_filter($array, 'trim'); foreach ($array as $line) { $domain = addslashes($line); $domain = preg_replace("/\r|\n/", "", $domain); $domain = strtolower($domain); $domain = str_replace("www.", "", $domain); $domain = str_replace(" ", "", $domain);
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 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 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? 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! I am trying to insert a variable into this post string: curl_setopt ($ch, CURLOPT_POSTFIELDS, 'p_entity_name=The+Company+Name+LLC&p_name_type=A&p_search_type=BEGINS'); I want to replace company name with $name like: curl_setopt ($ch, CURLOPT_POSTFIELDS, 'p_entity_name='+ $name + 'p_name_type=A&p_search_type=BEGINS'); Hi, I am trying to convert a String date into numeric date using PHP function's, but haven't found such function. Had a look at date(), strtotime(), getdate(); e.g. Apr 1 2011 -> 04-01-2011 Could someone please shed some light on this? Regards, Abhishek 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! 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 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 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! 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? 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. 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); 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) |