php-general Digest 8 Dec 2011 01:29:38 -0000 Issue 7601

Topics (messages 315944 through 315950):

Problem with date
        315944 by: Jack
        315945 by: Joshua Kehn
        315946 by: Jim Lucas
        315947 by: Jack Sasportas
        315948 by: Jack
        315949 by: Jack
        315950 by: admin.buskirkgraphics.com

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Hello All,

 

I have a problem where Dates are coming out as 12.31.1969 19:00:00 which of
course we didn't have PC's in 1969

I'm not able to see where the date is getting screwed up, any ideas??

 

//
############################################################################
#

function ShowFeed_RSS($XmlRoot) {

  $title = GetFirstChildContentByPath($XmlRoot, "channel/title");          

  $link = GetFirstChildContentByPath($XmlRoot, "channel/link");  

  $desc = GetFirstChildContentByPath($XmlRoot, "channel/description");

# Next 2 lines display the title of the feed, and feed description


#  echo "<font face=arial color=blue size =2><b><a
href=\"$link\">$title</a></b>\n";

#  echo "$desc";

  $nodelist = GetChildrenByPathAndName($XmlRoot, "channel", "item");

  if (!$nodelist) return 0;

  foreach ($nodelist as $nl) {

    $title   = GetFirstChildContentByName($nl, "title");

    $link    = GetFirstChildContentByName($nl, "link");

    $desc    = GetFirstChildContentByName($nl, "description");

    $creator = GetFirstChildContentByName($nl, "author");

 

#    if (!$creator) $creator = GetFirstChildContentByName($nl,
"dc:creator");

 

#       echo "JACK" . $nl . "<br>";

#    $pubdate = GetFirstChildContentByName($nl, "pubDate");

    if (!isset($pubdate)) $pubdate = GetFirstChildContentByName($nl,
"dc:date");

#    if (!$pubdate) $pubdate = GetFirstChildContentByName($nl, "dc:date");

    if (isset($pubdate)) $pubdate = strtotime($pubdate);

    if (isset($pubdate)) $pubdate = strftime("%m.%d.%Y %H:%M:%S", $pubdate);

    $out = $creator;

 

    if ( ($creator != "") && ($pubdate != "") ) $out .= " @ ";


        $out .= $pubdate;

        echo "<a class=\"rss-link\" href=\"$link\"><b>$title</b></a>";

        echo "<font size=1 color=\"black\">    $out<br>";

        echo "<font size=2>$desc<br><br>";

#       echo "<font size=1 class=rss-link>This is not green</font>";

 

}

#  this line is after each rss feed group

#  echo "<hr>\n";

 

}    

 

 

 

Thanks!

Jack

 


--- End Message ---
--- Begin Message ---
$pubdate is probably null or something.

Regards,

–Josh
____________________________________
Joshua Kehn | @joshkehn 
http://joshuakehn.com

On Dec 7, 2011, at 1:48 PM, Jack wrote:

> Hello All,
> 
> 
> 
> I have a problem where Dates are coming out as 12.31.1969 19:00:00 which of
> course we didn't have PC's in 1969
> 
> I'm not able to see where the date is getting screwed up, any ideas??
> 
> 
> 
> //
> ############################################################################
> #
> 
> function ShowFeed_RSS($XmlRoot) {
> 
>  $title = GetFirstChildContentByPath($XmlRoot, "channel/title");          
> 
>  $link = GetFirstChildContentByPath($XmlRoot, "channel/link");  
> 
>  $desc = GetFirstChildContentByPath($XmlRoot, "channel/description");
> 
> # Next 2 lines display the title of the feed, and feed description
> 
> 
> #  echo "<font face=arial color=blue size =2><b><a
> href=\"$link\">$title</a></b>\n";
> 
> #  echo "$desc";
> 
>  $nodelist = GetChildrenByPathAndName($XmlRoot, "channel", "item");
> 
>  if (!$nodelist) return 0;
> 
>  foreach ($nodelist as $nl) {
> 
>    $title   = GetFirstChildContentByName($nl, "title");
> 
>    $link    = GetFirstChildContentByName($nl, "link");
> 
>    $desc    = GetFirstChildContentByName($nl, "description");
> 
>    $creator = GetFirstChildContentByName($nl, "author");
> 
> 
> 
> #    if (!$creator) $creator = GetFirstChildContentByName($nl,
> "dc:creator");
> 
> 
> 
> #       echo "JACK" . $nl . "<br>";
> 
> #    $pubdate = GetFirstChildContentByName($nl, "pubDate");
> 
>    if (!isset($pubdate)) $pubdate = GetFirstChildContentByName($nl,
> "dc:date");
> 
> #    if (!$pubdate) $pubdate = GetFirstChildContentByName($nl, "dc:date");
> 
>    if (isset($pubdate)) $pubdate = strtotime($pubdate);
> 
>    if (isset($pubdate)) $pubdate = strftime("%m.%d.%Y %H:%M:%S", $pubdate);
> 
>    $out = $creator;
> 
> 
> 
>    if ( ($creator != "") && ($pubdate != "") ) $out .= " @ ";
> 
> 
>        $out .= $pubdate;
> 
>        echo "<a class=\"rss-link\" href=\"$link\"><b>$title</b></a>";
> 
>        echo "<font size=1 color=\"black\">    $out<br>";
> 
>        echo "<font size=2>$desc<br><br>";
> 
> #       echo "<font size=1 class=rss-link>This is not green</font>";
> 
> 
> 
> }
> 
> #  this line is after each rss feed group
> 
> #  echo "<hr>\n";
> 
> 
> 
> }    
> 
> 
> 
> 
> 
> 
> 
> Thanks!
> 
> Jack
> 
> 
> 


--- End Message ---
--- Begin Message ---
On 12/7/2011 10:48 AM, Jack wrote:
> Hello All,
> 
> I have a problem where Dates are coming out as 12.31.1969 19:00:00 which of
> course we didn't have PC's in 1969
> 
> I'm not able to see where the date is getting screwed up, any ideas??
> 
> //
> ############################################################################
> #
> function ShowFeed_RSS($XmlRoot) {
>   $title = GetFirstChildContentByPath($XmlRoot, "channel/title");          
>   $link = GetFirstChildContentByPath($XmlRoot, "channel/link");  
>   $desc = GetFirstChildContentByPath($XmlRoot, "channel/description");
> # Next 2 lines display the title of the feed, and feed description
> #  echo "<font face=arial color=blue size =2><b><a
> href=\"$link\">$title</a></b>\n";
> #  echo "$desc";
>   $nodelist = GetChildrenByPathAndName($XmlRoot, "channel", "item");
>   if (!$nodelist) return 0;
>   foreach ($nodelist as $nl) {
>     $title   = GetFirstChildContentByName($nl, "title");
>     $link    = GetFirstChildContentByName($nl, "link");
>     $desc    = GetFirstChildContentByName($nl, "description");
>     $creator = GetFirstChildContentByName($nl, "author");
> #    if (!$creator) $creator = GetFirstChildContentByName($nl,
> "dc:creator");
> #       echo "JACK" . $nl . "<br>";
> #    $pubdate = GetFirstChildContentByName($nl, "pubDate");
>     if (!isset($pubdate)) $pubdate = GetFirstChildContentByName($nl,
> "dc:date");
> #    if (!$pubdate) $pubdate = GetFirstChildContentByName($nl, "dc:date");
>     if (isset($pubdate)) $pubdate = strtotime($pubdate);
>     if (isset($pubdate)) $pubdate = strftime("%m.%d.%Y %H:%M:%S", $pubdate);
>     $out = $creator;
>     if ( ($creator != "") && ($pubdate != "") ) $out .= " @ ";
>         $out .= $pubdate;
>         echo "<a class=\"rss-link\" href=\"$link\"><b>$title</b></a>";
>         echo "<font size=1 color=\"black\">    $out<br>";
>         echo "<font size=2>$desc<br><br>";
> #       echo "<font size=1 class=rss-link>This is not green</font>";
> }
> #  this line is after each rss feed group
> #  echo "<hr>\n";
> }    
> Thanks!
> Jack

Can you supply an example of the data you are feeding this.

-- 
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
http://www.bendsource.com/

C - (541) 408-5189
O - (541) 323-9113
H - (541) 323-4219

--- End Message ---
--- Begin Message ---
> 
> 
>       How about a little debugging here (and possibly elsewhere):
> 
>       if (isset($pubdate) && ($pubdate >0)) {
>          $pubdate=strtotime($pubdate);
>       } else {
>          die("Barf.  Can't run a string to time conversion on 0 or -1.");
>       }
> 

Thanks Kevin,

This bombs and gives me the BARF!

--- End Message ---
--- Begin Message ---
> >       How about a little debugging here (and possibly elsewhere):
> >
> >       if (isset($pubdate) && ($pubdate >0)) {
> >          $pubdate=strtotime($pubdate);
> >       } else {
> >          die("Barf.  Can't run a string to time conversion on 0 or
-1.");
> >       }
> >
> 
Thanks Kevin,

This bombs and gives me the BARF!


--- End Message ---
--- Begin Message ---
> To: PHP
> Subject: RE: [PHP] Problem with date
> 
> >
> >
> >       How about a little debugging here (and possibly elsewhere):
> >
> >       if (isset($pubdate) && ($pubdate >0)) {
> >          $pubdate=strtotime($pubdate);
> >       } else {
> >          die("Barf.  Can't run a string to time conversion on 0 or
-1.");
> >       }
> >
> 
> Thanks Kevin,
> 
> This bombs and gives me the BARF!
> 

FYI the date field is stored in a MySQL DB as a datetime type


--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Jack [mailto:jacklistm...@gmail.com]
> Sent: Wednesday, December 07, 2011 1:49 PM
> To: PHP
> Subject: [PHP] Problem with date
> 
> Hello All,
> 
> 
> 
> I have a problem where Dates are coming out as 12.31.1969 19:00:00
> which of
> course we didn't have PC's in 1969
> 
> I'm not able to see where the date is getting screwed up, any ideas??
> 
> 
> 
> //
> #######################################################################
> #####
> #
> 
> function ShowFeed_RSS($XmlRoot) {
> 
>   $title = GetFirstChildContentByPath($XmlRoot, "channel/title");
> 
>   $link = GetFirstChildContentByPath($XmlRoot, "channel/link");
> 
>   $desc = GetFirstChildContentByPath($XmlRoot, "channel/description");
> 
> # Next 2 lines display the title of the feed, and feed description
> 
> 
> #  echo "<font face=arial color=blue size =2><b><a
> href=\"$link\">$title</a></b>\n";
> 
> #  echo "$desc";
> 
>   $nodelist = GetChildrenByPathAndName($XmlRoot, "channel", "item");
> 
>   if (!$nodelist) return 0;
> 
>   foreach ($nodelist as $nl) {
> 
>     $title   = GetFirstChildContentByName($nl, "title");
> 
>     $link    = GetFirstChildContentByName($nl, "link");
> 
>     $desc    = GetFirstChildContentByName($nl, "description");
> 
>     $creator = GetFirstChildContentByName($nl, "author");
> 
> 
> 
> #    if (!$creator) $creator = GetFirstChildContentByName($nl,
> "dc:creator");
> 
> 
> 
> #       echo "JACK" . $nl . "<br>";
> 
> #    $pubdate = GetFirstChildContentByName($nl, "pubDate");
> 
>     if (!isset($pubdate)) $pubdate = GetFirstChildContentByName($nl,
> "dc:date");
> 
> #    if (!$pubdate) $pubdate = GetFirstChildContentByName($nl,
> "dc:date");
> 
>     if (isset($pubdate)) $pubdate = strtotime($pubdate);
> 
>     if (isset($pubdate)) $pubdate = strftime("%m.%d.%Y %H:%M:%S",
> $pubdate);
> 
>     $out = $creator;
> 
> 
> 
>     if ( ($creator != "") && ($pubdate != "") ) $out .= " @ ";
> 
> 
>         $out .= $pubdate;
> 
>         echo "<a class=\"rss-link\" href=\"$link\"><b>$title</b></a>";
> 
>         echo "<font size=1 color=\"black\">    $out<br>";
> 
>         echo "<font size=2>$desc<br><br>";
> 
> #       echo "<font size=1 class=rss-link>This is not green</font>";
> 
> 
> 
> }
> 
> #  this line is after each rss feed group
> 
> #  echo "<hr>\n";
> 
> 
> 
> }
> 
> 
> 
> 
> 
> 
> 
> Thanks!
> 
> Jack
> 
> 



Suggestion only.
    if (isset($pubdate)) $pubdate = strtotime($pubdate);

    if (isset($pubdate)) $pubdate = strftime("%m.%d.%Y %H:%M:%S", $pubdate);

        could be 

    if (isset($pubdate)) $pubdate = mktime("m d Y
H:i:s",strtotime($pubdate));
        Reducing the code

I also changed this to MKtime from strftime because The %e modifier is not
supported in the Windows implementation of this function. To achieve this
value, the %#d modifier can be used instead. The example below  illustrates
how to write a cross platform compatible function. 

Please read on the MKTIME function
http://php.net/manual/en/function.mktime.php
















--- End Message ---

Reply via email to