PHP - Datetime To Atom
Hi Everyone,
Please have a look at this, and tell me if its right? I am generating a sitemap for my website dynamically. The date I am providing: 2012-02-24 11:56:09 and this is the output I am getting: 2012-02-24T11:56:09Z now I am not sure of the Z at the end of the returned value. I think I am looking for something similar to this: 2012-03-12T12:00:02+02:00 not to sure what I am doing wrong and where it gets the timezone from, I am guessing from the php config file. any help would be much appreciated. thanks My code: Code: [Select] <lastmod><?php echo $time->toAtom($post['Post']['modified']); ?></lastmod> Similar TutorialsDear all, how can I convert a string "yyyy-mm-dd hh:mm" into a really datetime value with php? thanks! Hi guys, im having problem on how to insert this code ... <atom:link href="######" rel="self" type="application/rss+xml" /> Code: [Select] <?php /** A.R.A Class RSS Builder (c) 2007 Denis Sureau http://www.scriptol.com/rss/ API for creating RSS 2.0 feeds Licence GNU GPL 2. */ // Create a feed // Returns the XML document class ara { public $doc; public $rss; public $channel; function ARAMakeTag($tagname, $str) { $tag= $this->doc->createElement($tagname); $data= $this->doc->createTextNode($str); $tag->appendChild($data); return $tag; } public function ARAFeed($title, $link, $desc, $date) { $this->doc = new DOMDocument("1.0", "UTF-8"); $this->doc->formatOutput = true; $this->rss = $this->doc->createElement("rss"); $this->rss->setAttribute("version", "2.0"); $this->rss->setAttribute("xmlns:atom", "http://www.w3.org/2005/Atom"); $this->doc->appendChild($this->rss); $this->channel = $this->doc->createElement("channel"); $this->rss->appendChild($this->channel); $this->channel->appendChild($this->ARAMakeTag("title", $title)); $this->channel->appendChild($this->ARAMakeTag("link", $link)); $this->channel->appendChild($this->ARAMakeTag("description", $desc)); $this->channel->appendChild($this->ARAMakeTag("pubDate", $date)); } public function ARAItem( $title, $id, $cid, $desc, $date) { $item = $this->doc->createElement("item"); $item->appendChild($this->ARAMakeTag("title", $title)); $item->appendChild($this->ARAMakeTag("link", "####")); $item->appendChild($this->ARAMakeTag("guid", "#####")); $item->appendChild($this->ARAMakeTag("description", $desc)); $item->appendChild($this->ARAMakeTag("pubDate", $date)); $this->channel->appendChild($item); } public function save($fname) { $this->doc->save($fname); } public function saveXML() { return $this->doc->saveXML(); } } ?> i would like to add this code to validate my rss feed.. <atom:link href="http://dallas.example.com/rss.xml" rel="self" type="application/rss+xml" /> thanks in advance guys.. Hello everyone, I am having problem trying to fetch data from certain feeds. The problem is, the feeds aren't just using XML or just atom, it is a combo of both. Here is an example of YouTube's feed: Code: [Select] <?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007'><id>http://gdata.youtube.com/feeds/api/videos/qzUuAIPPrGQ</id><published>2010-11-02T15:10:24.000Z</published><updated>2010-11-04T22:09:22.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/><category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Film' label='Film & Animation'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='mysteryguitarman'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='mystery'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='guitar'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='man'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='mgm'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='joe'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='penna'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='jp'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='balinese'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='bali'/><category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='instruments'/><title type='text'>Bali Instruments</title><content type='text'>Behind the Scenes: http://bit.ly/BehindTheScenesBali Click to Tweet: http://bit.ly/ClickToTweetBali Watch my other videos: http://www.youtube.com/MysteryGuitarMan My second channel: http://www.youtube.com/jp Twitter's cool... right? http://www.twitter.com/MysteryGuitarM Send me things: Mystery Guitar Man PO Box 2966 Hollywood, CA 90078 -Subtitles- Portuguese: http://youtube.com/ands159</content><link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=qzUuAIPPrGQ&feature=youtube_gdata'/><link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/qzUuAIPPrGQ/responses'/><link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/qzUuAIPPrGQ/related'/><link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=qzUuAIPPrGQ'/><link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/qzUuAIPPrGQ'/><author><name>MysteryGuitarMan</name><uri>http://gdata.youtube.com/feeds/api/users/mysteryguitarman</uri></author><gd:comments><gd:feedLink href='http://gdata.youtube.com/feeds/api/videos/qzUuAIPPrGQ/comments' countHint='10222'/></gd:comments><media:group><media:category label='Film & Animation' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Film</media:category><media:content url='http://www.youtube.com/v/qzUuAIPPrGQ?f=videos&app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='123' yt:format='5'/><media:content url='rtsp://v6.cache6.c.youtube.com/CiILENy73wIaGQlkrM-DAC41qxMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='123' yt:format='1'/><media:content url='rtsp://v3.cache7.c.youtube.com/CiILENy73wIaGQlkrM-DAC41qxMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='123' yt:format='6'/><media:description type='plain'>Behind the Scenes: http://bit.ly/BehindTheScenesBali Click to Tweet: http://bit.ly/ClickToTweetBali Watch my other videos: http://www.youtube.com/MysteryGuitarMan My second channel: http://www.youtube.com/jp Twitter's cool... right? http://www.twitter.com/MysteryGuitarM Send me things: Mystery Guitar Man PO Box 2966 Hollywood, CA 90078 -Subtitles- Portuguese: http://youtube.com/ands159</media:description><media:keywords>mysteryguitarman, mystery, guitar, man, mgm, joe, penna, jp, balinese, bali, instruments</media:keywords><media:player url='http://www.youtube.com/watch?v=qzUuAIPPrGQ&feature=youtube_gdata_player'/><media:thumbnail url='http://i.ytimg.com/vi/qzUuAIPPrGQ/2.jpg' height='90' width='120' time='00:01:01.500'/><media:thumbnail url='http://i.ytimg.com/vi/qzUuAIPPrGQ/1.jpg' height='90' width='120' time='00:00:30.750'/><media:thumbnail url='http://i.ytimg.com/vi/qzUuAIPPrGQ/3.jpg' height='90' width='120' time='00:01:32.250'/><media:thumbnail url='http://i.ytimg.com/vi/qzUuAIPPrGQ/0.jpg' height='240' width='320' time='00:01:01.500'/><media:title type='plain'>Bali Instruments</media:title><yt:duration seconds='123'/></media:group><gd:rating average='4.970053' max='5' min='1' numRaters='40338' rel='http://schemas.google.com/g/2005#overall'/><yt:statistics favoriteCount='10811' viewCount='705760'/></entry> What do you recommend doing to getting data out of feeds such as this? Thank you, weee This code gives me 1969-12-31 18:33:30 Code: [Select] <?=date('d M Y', $val['Created']);?> and this one gives me 2010-11-04 03:52:54 WHICH IS THE RIGHT ONE - BUT i need to format as above. Code: [Select] <?=$val['Created']?> this happens on the same line of code. What is wrong? Hello All, I have the following code: Code: [Select] echo "<table width='615px' cellpadding='3' cellspacing='4' align='center'>"; echo "<tr>"; echo "<td align='left' width='150px'>"; echo substr($row['date'],0,11); echo "</td>"; echo "<td align='left' width='465px'>"; echo $row["food"] ; echo "</td>"; echo "</tr>"; echo "</table>"; And this outputs: Apr 4 2011 Chicken Ceasar Salad, Garlic Toast, Cloddhoppers, Applesauce, & Milk (etc.) How can I add "Mon" in front of "Apr 4 2011"? thanks! Hello!! i want to save datetimes into a mysql database. Their format is dd-mm-yy hh:mm. I think mysql format for datetime is yy-mm-dd hh:mm..How can i convert them?? Hi, I'm a newbie here, and with PHP, and need some help with the datetime display. I am wanting to utilize old Naval comms DTG (datetimegroup) format which is DDHHMM 3-digit Month 2-digit year. The DDHHMM = Day (01 - 31) HH (hour 01 - 24) MM (minute 00 - 59) What I need to do is to add the letter Z (meaning GMT, ZULU) like thus DDHHMMZ FEB 11 How can I go about inserting that Z into this? Tks in advance for any assist Hey, does anybody know a good function, where I can have the trendy "time ago" functionality?
A good tutorial would be cool, too.
I would be using the datetime function off MySQL.
Code: [Select] OFXAdapter: Failed to parse request: Unable to parse an atomic field "OFXRequest.OFXRequest.SignOnMsgsRqUn.SignOnMsgsRqV1.SonRq.DtClient": field value "20101005091544.000[-4:EDT]" is not a valid (YYYYMMDDHHMMSS.XXX[gmt offset:tz name]) date. I am trying to put together some PHP code to use the OFX standard to communicate with my bank in order to download my recent transactions. The standard details that in the sign-on request, the date and time must be included in the format listed above. As you can see, I have the value in the exact same format as specified. So my question is this: is there something about GMT offset or TZ names that I am missing here? I'm given something like this: Sun Nov 06 2011 09:30:00 GMT-0500 (EST) And i'm trying to turn that into 2011-11-06 09:30:00 I started by using explode and trying to loop through the day and month to figure it out, but that seems inefficient and overly complicated. Am i missing something? Thanks Basically I am using DATETIME to store the time in which a row was input. Format - 2010-11-13 21:31:53 How would I get the current time of page load and compare it to the database row "2010-11-13 21:31:53" then output the difference. Example $sqlresult = 2010-11-13 21:31:53; $currentTime = (GET CURRENT DATE+TIME = (2010-11-13 21:31:55) ); Output - This was posted 2 minute's ago. Thank you in advance. Any help would be greatly appreciated. I'm having trouble inserting a formatted PHP DateTime into a MySQL table. I'm getting: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',2012-01-31)' at line 4 I get the error when I try to insert the date as a string from a DateTime object via: $insertDate = $date->format('Y-m-d'); As well as when I try to recast it as a date object: $insertDate = date("Y-m-d",strtotime($date->format('Y-m-d'))); I've also tried putting the date in ' ' 's and escaped " " 's. My insert query is: $insert = "INSERT INTO pendingordersdetails (PartNumber,Oqty,Pqty,Aqty,PartStatus, PartPrice,idOrderNo,PrtTariffCode,PrtLocation,LineNum,PKqty,SPqty,AllocationDate) VALUES ('$partNum',$oQty,0,$aQty,'Excess',$price,$orderNum,'$tariffCode', '$location',$lineNum,$PKqty,$SPqty,'$allocDate');"; and the echoed output is: INSERT INTO pendingordersdetails (PartNumber,Oqty,Pqty,Aqty,PartStatus, PartPrice,idOrderNo,PrtTariffCode,PrtLocation,LineNum,PKqty,SPqty,AllocationDate) VALUES ('0446535240 ',3,0,1,'Excess',163.89,66,' ', 'A0406E01',2,,,'2012-01-31'); Anyone have any ideas? Hi, so I am trying to get how many minutes and seconds are left from the datetime entry in the database and the current datetime, but I'm having issues... Here's my code: Code: [Select] $query = "SELECT RequestMadeDateTime FROM TempAwaitingClients WHERE PSOID = '2'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $RequestMadeDateTime = $row['RequestMadeDateTime']; $currentDateTime = date('Y-m-d H:i:s'); echo 'Request Made Date Time: ' . $RequestMadeDateTime . '<br />'; echo 'Current Date Time: ' . $currentDateTime . '<br />'; echo date_diff($RequestMadeDateTime, $currentDateTime); What I'm getting those is this, "Warning: date_diff() expects parameter 1 to be DateTime" ... Which I don't get because both variables are DateTime... I have a page where "Events" which may be of interest to site visitors can be recorded. Among other info, an "Event" has a "from" date and a "to" date (to show that an event will run from October 29th to October 31st, for example). All event info is being written to the db, but the "from" and "to" dates are not. (In the db, "0000-00-00 00:00:00" is being entered in the "from" and "to" columns.) In the Events table, both event_date and event_end_date are of type datetime. Dates are entered into the form fields via a javascript datepicker and are in the format "24/09/2011". I'm using this code: Code: [Select] // Check for a Start Date: if (empty($_POST['from'])) { $errors[] = 'You forgot to enter a Start Date for the event.'; } else { $from = $_POST['from']; } // Check for an End Date: if (empty($_POST['to'])) { $errors[] = 'You forgot to enter an End Date for the event.'; } else { $to = $_POST['to']; } The db query is this: Code: [Select] if (empty($errors)) { // If everything's OK. // Insert the Event info in the database... // Make the query: $q = "INSERT INTO events (title, event_date, event_end_date, venue, ext_link, blurb) VALUES ('$title', '$from', '$to', '$venue', '$ext_link', '$blurb') "; $r = @mysqli_query ($dbc, $q); // Run the query. if ($r) { // If it ran OK. // Print a message: echo "<h2>Event info added!</h2> <h3>Your entry is now visible on the <a href='index.php'>Home Page</a>.</h3> <p><a href='logout.php'><strong>Log out</strong></a></p> " ; mysqli_close($dbc); include('inc/footer.php'); exit(); And the form is this: Code: [Select] <form id="form1" name="form1" method="post" action="add_event.php"> <label for="title">Title</label> <input type="text" name="title" id="title" value="<?php if (isset($_POST['title'])) echo $_POST['title']; ?>" /> <script> $(function() { var dates = $( "#from, #to" ).datepicker({ defaultDate: "", changeMonth: true, numberOfMonths: 1, onSelect: function( selectedDate ) { var option = this.id == "from" ? "minDate" : "maxDate", instance = $( this ).data( "datepicker" ), date = $.datepicker.parseDate( instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings ); dates.not( this ).datepicker( "option", option, date ); } }); }); </script> <label for="from" >*From</label> <input type="text" name="from" id="from" value="<?php if (isset($_POST['from'])) echo $_POST['from']; ?>" /> <label for="to" ">*To</label> <input type="text" name="to" id="to" value="<?php if (isset($_POST['to'])) echo $_POST['to']; ?>" /> <label for="venue">*Venue</label> <input type="text" name="venue" id="venue" value="<?php if (isset($_POST['venue'])) echo $_POST['venue']; ?>" /> <label for="blurb">*Description</label> <textarea name="blurb" id="blurb" value="<?php if (isset($_POST['blurb'])) echo $_POST['blurb']; ?>" rows="5" ></textarea> <label for="ext_link">External link (optional, entered like "www.example.com")</label> <input type="text" name="ext_link" id="ext_link" value="<?php if (isset($_POST['ext_link'])) echo $_POST['ext_link']; ?>" /> <input type="submit" name="submit" value="Insert Event Info" class="submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> Can anyone tell me why the dates aren't being recorded? Any help will be greatly appreciated. Hi, basically i am parsing some rtf/word files and generating excel csv's for upload into mysql database....my issue is in one of the fields i want to store the value in the mysql datetime / date format but excel keeps reformating it. Any help on how to overcome this will be highly appreciated. I am trying to import into a csv file and filter the results to a particular user and only results based on the time the data was uploaded within one hour. In other words anything not uploaded within the last hour of the start_time will not appear in the csv file. Everything works fine except for the time part. I get no results at all with the 'and unix_timestamp........ For all I know possibly I am way off with my effort. The field name is start_time. Here is code below. Appreciate any help.
<code> header('Content-type: application/csv'); </code> It is my belief that when storing time in the DB, it should always be at UTC. Agree? My question is whether one should work with DateTimes with a specific time zone or only do so when displaying the time to the user? For example, if I have multiple users which have a timezone string property based on their physical location as well as a datatime property when some event occurred for the given user, and need to implement some logic if the event occurred more than a given duration from the current time, which of the following approaches should be used? $currentTime = new DateTimeImmutable(); $userEventTime = new DateTime($queryResults['theEventField']); if($currentTime->sub(new DateInterval('P10D')) < $userEventTime) { //Display time to the user $displayEventTime = new DateTime('@'.$userEventTime->getTimestamp(), new DateTimeZone($queryResults['userTimeZone']))->format('Y-m-d H:i:sP'); }
$currentTime = new DateTimeImmutable('now', new DateTimeZone($queryResults['userTimeZone'])); $userEventTime = new DateTime($queryResults['theEventField'], new DateTimeZone($queryResults['userTimeZone'])); if($currentTime->sub(new DateInterval('P10D')) < $userEventTime) { //Display time to the user $displayEventTime = $userEventTime->format('Y-m-d H:i:sP'); }
I am preparing $begin and $end for DatePeriod() but I can't get passed this error "getting the error Recoverable fatal error: Object of class DateTime could not be converted to string". $today = date("Y-m-d"); $datestop=$_POST['datestop']; //echo "$today<br /><br />$datestop<br /><br />"; $begin = new DateTime("$today"); $end = new DateTime("$datestop");
Hi all, I am currently storing dates and times for certain events in the following format: $now= date('Y-m-d H:i:s'); This variable is then stored in a MySQL field of type DATETIME. I am looking for a way to query the database to return all results in a certain month, or within a certain time range, or a certain year etc. How would this be achieved? e.g. If I wanted to select everything for the year 2009, would it be: SELECT * FROM table WHERE date BETWEEN '2009-01-01 00:00:00' AND '2009-12-31 11:59:59' ? Thanks! I have multiple datetimes. The format is dd-mm-yy, hh:mm. I want to insert it into a table using mysql. However mysql format is yy-mm-dd, hh:mm:ss. How can i do it and what type should i use (datetime?timestamp?). Thanks for your help!! |