Page is a not externally linkable
- Code, Content, and Presentation
-- RSS, ATOM, and Related Technologies
---- Can I remove the time from pubDate?


gdwebdesign - 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]


Thread source:: http://www.webmasterworld.com/rss_atom/3694348.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com