Jump to content

Date Question


gaza165

Recommended Posts

Maybe if i post the code im doing you can better understand.

 

 

<?php
$feed = file_get_contents("events.xml");
$xml = new SimpleXmlElement($feed);
$time = time();
foreach ($xml->channel->item as $entry){
  
  $dc = $entry->children("http://purl.org/dc/elements/1.1/");
  $geo = $entry->children("http://www.w3.org/2003/01/geo/wgs84_pos#");
  
  echo "Title: ".$entry->title."</br>";

  //Dates that event is on.
  foreach($dc as $date) {

echo "Date: ".strtotime($date)."<br/>";

  }
  
  //Geo Location - Latitude and Londitude
echo "Lat: ".$geo[0]."<br/>";
echo "Long: ".$geo[1]."<br/>";
  
  
  
  echo "------------------------------------------------------------<br/>";
  
  
  
}

?>

Link to comment
https://forums.phpfreaks.com/topic/214203-date-question/#findComment-1114548
Share on other sites

To find the closest to a value, you take the absolute value of the difference between the current value and the values in question. If you order the results of that in ascending order, the smallest value will be the same or closest to the current value.

 

Untested, but should work -

 

SELECT *, ABS(UNIX_TIMESTAMP() - your_date_column) as diff FROM your_table ORDER BY diff LIMIT 1

 

Edit: If your columns are actually a DATE or DATETIME, instead of the unix timestamp you showed in your first post, you would alter the above query to use the TIMEDIFF() function and either NOW() or CURDATE() inside of the ABS() function.

Link to comment
https://forums.phpfreaks.com/topic/214203-date-question/#findComment-1114551
Share on other sites

What im trying to do is this... I have an XML File and i want to sort the events out by date

 

So like

 

26th Septemeer

 

List of all the events that have this date in their <dc:date> field.

 

28th September

 

List of all the events that have this date in their <dc:date> field.

 

 

XML FILE

 

<?xml version="1.0" encoding="UTF-8"?>
<rss version='2.0'   xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:xCal="urn:ietf:params:xml:ns:xcal" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" >
        
<channel>

    <item>
        <title><![CDATA[15 Feb 2010 - 10 Oct 2010: Funk, Soul, Disco, Hiphop]]></title>
        <geo:lat>51.74713</geo:lat><geo:long>-1.23755</geo:long>
        <dc:date>2010-09-25T01:00:00+01:00</dc:date>
        <dc:date>2010-10-02T01:00:00+01:00</dc:date>
        <dc:date>2010-10-09T01:00:00+01:00</dc:date>

    </item>
    
        <item>
            <title><![CDATA[26 Feb 2010 - 26 Oct 2010: Get Down]]></title>
            <geo:lat>51.74707</geo:lat><geo:long>-1.2351</geo:long>
            <dc:date>2010-09-24T01:00:00+01:00</dc:date>
            <dc:date>2010-10-01T01:00:00+01:00</dc:date>
            <dc:date>2010-10-08T01:00:00+01:00</dc:date>
            <dc:date>2010-10-15T01:00:00+01:00</dc:date>
            <dc:date>2010-10-22T01:00:00+01:00</dc:date>
        </item>



</channel>
</rss>

Link to comment
https://forums.phpfreaks.com/topic/214203-date-question/#findComment-1114560
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.