Date/Time. Looked Everywhere. Urgent. Thanks.

Discussion in 'ASP .Net' started by Shapper, Jun 17, 2005.

  1. Shapper

    Shapper Guest


    I created a dataset from a XML file. One of the dataset fields is

    In an ASP:Repeater I am displaying the [pubDate] field.
    <%# DataBinder.Eval(Container.DataItem, "pubDate", "{0:f}") %>

    The date displayed has the following format, the same as in the XML
    Fri, 20 May 2005 12:30:00 GMT

    I also tried "{0:F}", "{0:g}") as in:

    I am not able to change the date format.

    Even when I change culture the date weekday and month don't change.

    It seems the dataset is not recognizing the [pubDate] as date/time...

    Can someone help me?

    I have been trying to solve this for the past 2 days.

    Shapper, Jun 17, 2005
    1. Advertisements

  2. Shapper

    Patrice Guest

    What if you get the type of this object ? Is this a DateTime or a String ?

    Patrice, Jun 17, 2005
    1. Advertisements

  3. Shapper

    Shapper Guest


    You are saying to check what is the type of the [pubDate] field in my
    dataset? How can I do that?


    Shapper, Jun 17, 2005
  4. Shapper

    Patrice Guest

    Instead of printing the value, print
    Container.DataItem("pubDate").GetType.ToString. I should allow to find out :
    - if the type is not the one expected, it would direct then to a problem in
    the XML file
    - if the type is the one expected, it would direct then to a formatting

    For now I would say 1 is more likely...



    Patrice, Jun 17, 2005
  5. Shapper

    Hans Kesting Guest

    "the same as in XML" seems to mean that the XML file itself contains
    the string "Fri, 20 ...". This is not the standard way to write dates into
    an XML file! Standard is "yyyy-mm-ddThh:mm:ss.ffff" (not sure the "ffff"
    is required)

    I've never tried to go from XML to DataSet (only the other direction), but
    should that converion be able to pick up number and date fields? Or would
    all fields be strings? The XML file itself knows only strings!

    Hans Kesting
    Hans Kesting, Jun 17, 2005
  6. Shapper

    Shapper Guest


    Yep, I get System.String.

    Is it possible, before bind the dataset to the datagrid, to change the
    format of field [pubDate] from System.String to DateTime?

    Then I suppose it would work?


    Shapper, Jun 17, 2005
  7. Shapper

    Shapper Guest


    This XML file is a RSS file.
    Here is the RSS 2.0 Standard Format. Check the date.

    This is why I have the date in that format.


    Shapper, Jun 17, 2005
  8. Shapper

    Patrice Guest

    Yes, how do you load data ? I would use a DateTime field not only just
    before databinding but from the very beginning (if this is loaded for you,
    you could likely add a datetime column, transfer the string to the datetime
    column and drop the string column).


    Patrice, Jun 17, 2005
  9. Shapper

    Shapper Guest


    I asked you how I would change the format of the [pubDate] field in my
    dataset from "String" to "DateTime" because I am having huge problems in
    doing that when I load the data to the dataset.

    I am loading the data from a XML file.

    Here is a copy of a message I post to try to find a solution:

    "I have a XML file (RSS 2.0 format). Something as follows:

    <?xml version="1.0"?>
    <rss version="2.0">
    <description>Latest News</description>
    <pubDate>Fri, 20 May 2005 12:30:00 GMT</pubDate>

    I need to do the following:
    1. Get last 10 items according to its pubDate.
    2. Get the data of these items form the XML to the DataSet.
    3. Make the pubDate in each DataSet row as a standard ASP.Net format.

    In this moment I was able to load all items to a dataset but I wasn't
    able to fulfill the objectives as I described in (1) and (3).

    Here is my code:

    Dim news As New XmlDocument()
    Dim x As Integer
    Dim xNodeList As XmlNodeList =
    Dim dsNews As DataSet = New DataSet()
    Dim xReader As XmlTextReader
    For x = 0 To xNodeList.Count-1
    xReader = New XmlTextReader(xNodeList.item(x).OuterXml,
    XmlNodeType.Element, new XmlParserContext(Nothing, Nothing, Nothing,
    dsNews.ReadXml(xReader, XmlReadMode.InferSchema) Next x

    What do you think?

    Thank You,

    Shapper, Jun 17, 2005
  10. Shapper

    Sean M Guest

    How about using DateTime.Parse() with an IFormatProvider?

    For example, to parse a date specified in the US English format:

    System.IFormatProvider ifProvider = new
    System.Globalization.CultureInfo("en-US", false);

    string strDate = "January 1, 2006";

    DateTime dtDate = DateTime.Parse(strDate, ifProvider);

    Sean M, Jun 17, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.