Menu

Date format manipulation

Help
Jim
2012-08-09
2012-09-04
  • Jim

    Jim - 2012-08-09

    Are there any examples of changing the date format from the scrape to the
    output file?

    Thanks

    Jim

     
  • Selvin Fehric

    Selvin Fehric - 2012-08-09

    You can change it using javascript date functions. Give example what you want
    to do.

     
  • Jim

    Jim - 2012-08-22

    Below is my code that works great so far but I would like to reformat the date
    that is pulled from the content:

    let $date := data($doc//div/h2)

    the date is retrieved as "July 30, 2012" but I would like to convert it to
    rss2 RFC 822 format "Mon, 30 Jul 2012 0:00:01 GMT"

    Some direction would be greatly appreciated.

    <template>
                <![CDATA[ <rss version="2.0"><channel><title>News</title><lastBuildDate>${sys.datetime("EEE, dd MMM yyyy HH:mm:ss z")}</lastBuildDate><language>en-us</language> ]]>
            </template>
            <loop item="articleUrl" index="i">
                <!-- collects URLs of all articles from the front page -->
                <list>
                    <xpath expression="//a[1]/@href">
                        <html-to-xml>
                            <http url="${startUrl}"/>
                        </html-to-xml>
                    </xpath>
                </list>
                <!-- downloads each article and extract data from it -->
                <body>
                    <empty>
                        <var-def name="item_link">          
                            <template>${sys.fullUrl(startUrl, articleUrl)}</template>
                        </var-def>
                    </empty>
                    <xquery>
                        <xq-param name="doc">                                             
                            <html-to-xml>
                                <http url="${sys.fullUrl(startUrl, articleUrl)}"/>
                            </html-to-xml>
                        </xq-param>                    
                        <xq-param name="link" type="string">
                            <var name= "item_link"/>            
                        </xq-param>                    
                        <xq-expression><![CDATA[
                            declare variable $doc as node() external;
                            declare variable $link as xs:string+ external;                                          
                            let $date := data($doc//div[@id="main"]/h2[@class="date"])
    
                            let $title := data($doc//div[@id="main"]/h1)
                            let $text := data($doc//div[@id="main"]/p[1])
                                return
                                    <item>
                                        <link>{data($link)}</link>
                                        <title>{data($title)}</title>
                                        <pubDate>{data($date)}</pubDate>
                                        <description>{data($text)}</description>
                                    </item>
                        ]]>
                        </xq-expression>
                    </xquery>               
                </body>
            </loop>
            <![CDATA[ </channel></rss> ]]>
    
     

Log in to post a comment.