1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

convert string to datetime????

Discussion in 'C#' started by ludwig, Jun 10, 2006.

  1. #1
    HI,

    I have
    strPubDate = "Sat, 10 Jun 2006 11:21:00 GMT"
    Code (markup):
    How do I best convert it to
    strPubDate = "10 Jun 2006 (11:21 GMT)"
    Code (markup):
    I need this for a site that uses RSS and I have to convert the datetime.

    Thanks in advance
     
    ludwig, Jun 10, 2006 IP
  2. jaymcc

    jaymcc Peon

    Messages:
    139
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hmmmm, i don't know if there is an easy way to do this.

    I would do something like this:
    - Convert the string to an actual date value with DateValue() function
    - Do some string contcatenation using datepart() to put together the string that you need with some spaces and (s where you need them.

    Kinda messy. It's actually something that you can do easily in VB, but not VBScript. In the past I used to use a COM object I created in VB 6 that just called the format function, to which you could pass a picture or mask string and it would return it back exactly as needed. Lost now, don't even have VB6 installed anymore.

    Hope this helps.

    J
     
    jaymcc, Jun 11, 2006 IP
  3. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #3
    this is how I solved it, though its a temporary solution there should be some other way:

    
    strPubDate = right(strPubDate, 25)
    strPubTime = right(strPubDate, 12)
    strPubDate = left(strPubDate, 12)
    Response.Write("<strong>" & strPubDate & " (" & strPubTime & ")</strong>" & vbCrLf)
    
    Code (markup):
     
    ludwig, Jun 11, 2006 IP
  4. pher

    pher Well-Known Member

    Messages:
    403
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    125
    #4
    You could use the XmlTextWriter object.

    This is from memory, so it is possible that it won't work...

    
    Imports System.Xml
    
    Dim writer as New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
    writer.WriteStartDocument()
    writer.WriteStartElement("RSS")
    writer.WriteAttribute("version", "2.0")
    writer.WriteStartElement("channel")
    writer.WriteElement(""title", "Pher was here")
     ^^^
    This is for the main channel
    
    writer.WriteStartElement("item")
    writer.WriteElement("title", "Pher was here too")
    writer.WriteElement("pubdate", DateTime.Now.ToString("R"))
    writer.WriteEndElement()
    ^^^
    Item code
    
    writer.Flush()
    writer.Close()
    
    
    Code (markup):
    Hope this helps...
     
    pher, Jun 19, 2006 IP