SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: FormatDate

  1. #1
    SitePoint Member
    Join Date
    Apr 2010
    Location
    Eindhoven
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    FormatDate

    I have a RSS feed and i need to change the format of time.
    In the RSS I will get this date format:

    Thu, 20 May 2010 11:25:05 +0200

    I need it to become this format:

    20/5/2010

    When I do this FormatDateTime(date,2) I will get an error.


    Is there another sollution?

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If the returned date ALWAYS has the + and the , in it then ...

    Code ASP:
    <%
    AllOK = False
    sDate = "Thu, 20 May 2010 11:25:05 +0200"
    aDate = Split (sDate, "+")
    If Ubound (aDate) > 0 Then
    	sDate1 = Trim (aDate(0))
    	aDate = Split (sDate1, ",")
    	If Ubound (aDate) > 0 Then
    		sDate2 = Trim (aDate(1))
    		fDate = FormatDateTime (sDate2,2)
    		AllOK = True
    	End If
    End If
    If AllOK Then Response.Write sDate & " : " & fDate
    %>
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Member
    Join Date
    Apr 2010
    Location
    Eindhoven
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks siteguru, but I'm getting the following error:

    Microsoft VBScript runtime error '800a000d'

    Type mismatch: 'FormatDateTime'

    /test.asp, line 26: fDate = FormatDateTime (sDate2,2)

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I would need to see your actual code. The example I posted works fine on my local server. (I tested the code before posting it. )

    Most likely the issue is that the original date data is not exactly as you suggested.
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Member
    Join Date
    Apr 2010
    Location
    Eindhoven
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code ASP:
    <%
    	Set xmlObj = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
    	xmlObj.async = False
    	xmlObj.setProperty "ServerHTTPRequest", True
    	xmlObj.Load("http://www.rechtennieuws.nl/forum/topics_anywhere.php?mode=show&out=rss2.0&bhpcat=11&n=10&sfn=y&r=y&sr=y&b=non&lpb=0&h=asmpl&lpd=5&last_topics=y")
    	If xmlObj.parseError.errorCode <> 0 Then
    		Response.Write "ERROR"
    	End If
    	Set xmlList = xmlObj.getElementsByTagName("item")
    	Set xmlObj = Nothing
    	x = 1
    	For Each xmlItem In xmlList 
    		If x < 6 then
    			title = xmlItem.childNodes(1).text
     
    			sDate = xmlItem.childNodes(0).text
    			aDate = Split (sDate, "+")
    			If Ubound (aDate) > 0 Then
    			    sDate1 = Trim (aDate(0))
    			    aDate = Split (sDate1, ",")
    			    If Ubound (aDate) > 0 Then
    			        sDate2 = Trim (aDate(1))
    			        fDate = FormatDateTime (sDate2,2)
    			    End If
    			End If
     
    			Response.Write "<li>" & fDate & " <a href='juridisch-nieuws.asp?xid=" & x & "' title='" & title & "'>"  & StripText(title) & "</a></li>"
    		End if
    		x = x + 1
    	Next
    	Set xmlList = Nothing
    %>

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Testing your code I get an error on line 27 ...

    Code:
    Response.Write "<li>" & fDate & " <a href='juridisch-nieuws.asp?xid=" & x & "' title='" & title & "'>"  & StripText(title) & "</a></li>"
    ... and it is the StripText function that causes the problem - because it doesn't exist. What is this supposed to do? What about replacing it with Trim?
    Ian Anderson
    www.siteguru.co.uk

  7. #7
    SitePoint Member
    Join Date
    Apr 2010
    Location
    Eindhoven
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Verry strange. That function I forgot to put in the test page. But I get this error (also when I delete that function StripText):

    Microsoft VBScript runtime error '800a000d'

    Type mismatch: 'FormatDateTime'

    /test.asp, line 23

  8. #8
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tested the code and it worked fine on my server after removing "stripText" function....

  9. #9
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hmm. It works fine for me. What if you do this (below) - what output do you get? Mine is shown below.

    Code ASP:
                sDate = xmlItem.childNodes(0).text
    			Response.Write sDate & "<br>"
                aDate = Split (sDate, "+")
    Code:
    Thu, 20 May 2010 11:25:05 +0200
    # 20/05/2010 Rechter: oud-topman Fortis moet komen in Ondernemingsrecht
    Thu, 20 May 2010 11:25:01 +0200
    # 20/05/2010 Jaarverslag: Bijna twee miljoen rechtszaken in 2009 in Algemeen
    Thu, 20 May 2010 11:20:07 +0200
    # 20/05/2010 Doorbraak: burn-out nu objectief aan te tonen in Gezondheidsrecht
    Thu, 20 May 2010 11:20:02 +0200
    # 20/05/2010 Ex-Fortistop weigert naar Nederland te komen in Ondernemingsrecht
    Thu, 20 May 2010 11:20:01 +0200
    # 20/05/2010 Technologie wordt steeds belangrijker reguleringsinstrument in Recht en technologie
    I'm wondering if it is something to do with regional settings ... what if you put this at the top of the page?

    Code ASP:
    <%
    Session.LCID = 2057
    If I use Session.LCID = 1043 (Dutch Standard) I also get the error message.

    http://support.microsoft.com/?kbid=229690
    Ian Anderson
    www.siteguru.co.uk

  10. #10
    SitePoint Member
    Join Date
    Apr 2010
    Location
    Eindhoven
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It was something with the regional settings! Thanks a lot!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •