Re: Date/Time. Looked Everywhere. Urgent. Thanks.



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);

"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:eLELN71cFHA.1448@xxxxxxxxxxxxxxxxxxxxxxx
> Hello,
>
> 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">
> <channel>
> <title>News</title>
> <description>Latest News</description>
> <item>
> <title>Title</title>
> <link>Url</link>
> <description>Description</description>
> <pubDate>Fri, 20 May 2005 12:30:00 GMT</pubDate>
> </item>
> ...
>
> 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()
> news.Load("http://www.domain.com/news.rss";)
> Dim x As Integer
> Dim xNodeList As XmlNodeList =
> news.SelectNodes("/rss[@version='2.0']/channel/item")
> 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,
> XmlSpace.None))
> dsNews.ReadXml(xReader, XmlReadMode.InferSchema) Next x
> "
>
> What do you think?
>
> Thank You,
> Miguel
>
> "Patrice" <nobody@xxxxxxxxxxx> wrote in message news:nobody@xxxxxxxxxxx:
>
> > 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
> >
> >
> >
> > "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> a écrit dans le
message
> > de news:%23ft9Hy0cFHA.3864@xxxxxxxxxxxxxxxxxxxxxxx
> >
> > > Hello,
> > >
> > > 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?
> > >
> > > Thanks,
> > > Miguel
> > >
> > > "Patrice" <nobody@xxxxxxxxxxx> wrote in message
news:nobody@xxxxxxxxxxx:
> > >
> >
> > > > 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
> > > > issue
> > > >
> > > > For now I would say 1 is more likely...
> > > >
> > > > Patrice
> > > >
> > > > --
> > > >
> > > > "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> a écrit dans le
> >
> > message
> >
> > > > de news:OIkRVd0cFHA.3940@xxxxxxxxxxxxxxxxxxxxxxx
> > > >
> >
> > > > > Hi,
> > > > >
> > > > > You are saying to check what is the type of the [pubDate] field in
my
> > > > > dataset? How can I do that?
> > > > >
> > > > > Thanks,
> > > > > Miguel
> > > > >
> > > > > "Patrice" <nobody@xxxxxxxxxxx> wrote in message
> >
> > news:nobody@xxxxxxxxxxx:
> >
> > > > >
> > > >
> >
> > > > > > What if you get the type of this object ? Is this a DateTime or
a
> >
> > String
> >
> > > >
> > > > ?
> > > >
> >
> > > > > >
> > > > > > Patrice
> > > > > >
> > > > > > --
> > > > > >
> > > > > > "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> a écrit dans
le
> > > >
> >
> > > > message
> > > >
> >
> > > > > > de news:uK%23MLF0cFHA.2436@xxxxxxxxxxxxxxxxxxxxxxx
> > > > > >
> > > >
> >
> > > > > > > Hello,
> > > > > > >
> > > > > > > I created a dataset from a XML file. One of the dataset fields
is
> > > > > > > [pubDate].
> > > > > > >
> > > > > > > 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
> >
> > > > > > > file:
> > > > > > > Fri, 20 May 2005 12:30:00 GMT
> > > > > > >
> > > > > > > I also tried "{0:F}", "{0:g}") as in:
> > > > > > >
> > > > > >
> > > >
> > > > > >
> > > >
> >
> > > >
> >
> >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafmtnameddateformats.asp
> >
> > > >
> >
> > > > > >
> > > >
> >
> > > > > > >
> > > > > > > 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.
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Miguel
> > > > > > >
> > > >
> > > > >
> >
> > >
>


.



Relevant Pages

  • Re: Date/Time. Looked Everywhere. Urgent. Thanks.
    ... 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. ... Dim news As New XmlDocument ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: problem with now()
    ... I still initialize forever a datetime as it has a date with: ... SQL parameters would also do the job and is ofcourse favored, however if the OP is sticking to concanated SQL then ISO 8601 would sure solve his problem ... The advantage in using the ISO 8601 format is that it is an international standard. ... Dim AA As MySqlConnection = New MySqlConnection("server=" & MYSQLServer ...
    (microsoft.public.dotnet.languages.vb)
  • Re: date formats
    ... Regex ... Dim dt As DateTime ... MessageBox.Show("Invalid date format") ...
    (microsoft.public.dotnet.languages.vb)
  • TimeSpace.Parse() usage
    ... ive read the MSDN docs on using the TimeSpace.Parsmethod to format ... timespans, however i found their examples unclear. ... Dim startTime As DateTime = DateTime.Now ...
    (microsoft.public.dotnet.framework)
  • Re: Setting field properties in code
    ... format that the user has defined in the Windows Control Panel, ... >> Sub StandardProperties(strTableName As String) ... >> Dim tdf As DAO.TableDef 'Table nominated in argument. ... >> Dim ind As DAO.Index ...
    (comp.databases.ms-access)

Quantcast