homepage Welcome to WebmasterWorld Guest from 54.227.41.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / RSS, ATOM, and Related Technologies
Forum Library, Charter, Moderators: bill & werty

RSS, ATOM, and Related Technologies Forum

    
Can I remove the time from pubDate?
Trim time off the date on an RSS feed
gdwebdesign




msg:3694350
 1:29 pm on Jul 9, 2008 (gmt 0)

I am using ASP to create an RSS feed from a database. I eventually managed to get the date to display by writing an ASP function that converted my date into a format that the XML could convert. My problem now is that the database does not hold the time and each date is displayed with 00:00:00. Is there any way I can remove the time from the RSS feed?

My code is below:

Thanks

Graeme

<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<title>News</title>
<link>http://www.example.co.uk/news/</link>
<%
''Response.end
Response.Buffer = true
Response.ContentType = "text/xml"

Dim Connection
Dim Recordset
Dim SQL

Function ApplyXMLFormatting(strInput)
strInput = Replace(strInput,"&", "&amp;")
strInput = Replace(strInput,"'", "&apos;")
strInput = Replace(strInput,"""", "&quot;")
strInput = Replace(strInput, ">", "&gt;")
strInput = Replace(strInput,"<","&lt;")

ApplyXMLFormatting = strInput
End Function

Function FormatDateInXMLStyle(datDate)
FormatDateInXMLStyle = _
WeekdayName(Weekday(datDate), True) & ", " & _
Right("0" & Day(datDate), 2) & " " & _
MonthName(Month(datDate), True) & " " & _
Right("000" & Year(datDate), 4) '& " " & _
'Right("0" & Hour(datDate), 2) & ":" & _
'Right("0" & Minute(datDate), 2) & ":" & _
'Right("0" & Second(datDate), 2) & " GMT"

'e.g. Sat, 07 Sep 2002 09:42:31 GMT
End Function

SQL = "SELECT DISTINCT DocID, DocTitle, HTMLfile, PDFfile, DatePublished, Orderable, BriefDescription FROM vwSearch where SectionID=11 ORDER BY DatePublished DESC"

Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")

Connection.Open "provider=sqloledb;data source=www_alias;initial catalog=company;Integrated Security=SSPI"

Recordset.Open SQL,Connection

If Recordset.EOF Then
Response.Write("No records returned.")
End If

Do While NOT Recordset.Eof
%>
<item>
<title><%=ApplyXMLFormatting(Recordset("DocTitle"))%></title>
<%if Recordset("HTMLfile") <> "" then %>
<link>http://www.example.co.uk/news/files/<%=ApplyXMLFormatting(Recordset("HTMLfile"))%></link>
<%else%>
<link>http://www.example.co.uk/news/files/<%=ApplyXMLFormatting(Recordset("PDFfile"))%></link>
<%end if%>

<pubDate>

<%
=ApplyXMLFormatting(FormatDateInXMLStyle(Recordset("DatePublished")))
%>

</pubDate>

<description><%=ApplyXMLFormatting(Recordset("BriefDescription"))%></description></item><%
Recordset.MoveNext
Loop
Recordset.Close()
Set Recordset=nothing
Connection.Close
Set Connection=nothing
%></channel></rss>

[edited by: bill at 1:00 am (utc) on July 10, 2008]
[edit reason] Use example.com or example.co.uk for Examples [/edit]

 

eelixduppy




msg:3699580
 6:47 am on Jul 16, 2008 (gmt 0)

Hello and Welcome to WebmasterWorld! :)

If you don't want the date you shouldn't be selecting it for use from your table. Try changing the query to the following and see what you get:

SQL = "SELECT DISTINCT DocID, DocTitle, HTMLfile, PDFfile, Orderable, BriefDescription FROM vwSearch where SectionID=11"

phranque




msg:3699624
 7:51 am on Jul 16, 2008 (gmt 0)

welcome to WebmasterWorld [webmasterworld.com], gdwebdesign!

the pubdate is specified according to RFC 822 which shows that the date is not optional:
[w3.org...]

gdwebdesign




msg:3699819
 1:11 pm on Jul 16, 2008 (gmt 0)

eelixduppy - I do want the date, just not the time!

phranque - Is there a way I can strip the time off, I don't really understand the link you sent me?

eelixduppy




msg:3700009
 5:00 pm on Jul 16, 2008 (gmt 0)

I think I understand what you want here. Try the following code:

<pubDate>
<%
dateString = Replace(Recordset("DatePublished"), "00:00:00", "")
Response.Write(ApplyXMLFormatting(FormatDateInXMLStyle(dateString)))
%>
</pubDate>

>> I don't really understand the link you sent me

He meant that you cannot get rid of "pubDate: from your RSS feed, which I've come to realize that you aren't, you just want to format the date/time differently since all the times are at 00:00:00. Try my changes above and see where that brings you.

phranque




msg:3700022
 5:20 pm on Jul 16, 2008 (gmt 0)

sorry - my error!
actually what i meant was you can't get rid of the time field from the format of your pubdate - the time is not optional.
regarding eelixduppy's workaround, i don't know if this will be a problem as i'm not sure 00:00:00 will be considered a valid time in any time zone...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / RSS, ATOM, and Related Technologies
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved