Welcome to WebmasterWorld Guest from 54.234.8.146

Forum Moderators: bill & werty

Message Too Old, No Replies

Can I remove the time from pubDate?

Trim time off the date on an RSS feed

     

gdwebdesign

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

5+ Year Member



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

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

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



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

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

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

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

5+ Year Member



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

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

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



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

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

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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...
 

Featured Threads

Hot Threads This Week

Hot Threads This Month