String to DateTime Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lee

    #1

    String to DateTime Problem



    Hello all,

    I'm trying to solve a problem with a string to datetime conversion.
    The problem arises when I try to convert a string from an XML doc into
    a .net DateTime. I'm manually creating a dataset from scratch and
    adding the fields and their DataTypes, appending to new datatable, etc.

    I've googled extensively until the wee hours of the morning and just
    can't seem to get this to work.

    The format of the string is:
    '02/24/2005 13:00:00'

    I have tried several ways around it to no avail. If I use
    DateTime.Parse( sValue); then it truncates to just a Date. Even then
    the field shows as null in a DataGrid after the routine is over.

    If I try:

    myDateTime := DateTime.ParseE xact('mm/dd/yyyy HH:NN:SS');

    ...an exception is raised with Invalid DateTime Value.


    --
    Warm Regards,

    Lee
  • Armin Zingler

    #2
    Re: String to DateTime Problem

    "Lee" <luv2program200 0@yahoo.com> schrieb[color=blue]
    > The format of the string is:
    > '02/24/2005 13:00:00'
    >
    > I have tried several ways around it to no avail. If I use
    > DateTime.Parse( sValue); then it truncates to just a Date. Even then
    > the field shows as null in a DataGrid after the routine is over.
    >
    > If I try:
    >
    > myDateTime := DateTime.ParseE xact('mm/dd/yyyy HH:NN:SS');
    >
    > ..an exception is raised with Invalid DateTime Value.[/color]


    I'd try:

    myDateTime = DateTime.ParseE xact("MM/dd/yyyy HH:mm:ss')


    see also:
    http://msdn.microsoft.com/library/en...matstrings.asp


    Armin

    Comment

    • Lee

      #3
      Re: String to DateTime Problem

      Armin Zingler enlightened me by writing:

      [color=blue]
      >
      > I'd try:
      >
      > myDateTime = DateTime.ParseE xact("MM/dd/yyyy HH:mm:ss')
      >
      >
      > see also:
      > http://msdn.microsoft.com/library/en...oncustomdateti
      > meformatstrings .asp
      >
      >
      > Armin[/color]

      That works better, Armin. Thank you. Looks like I need to study the
      formatting templates in .net a bit more.


      --
      Warm Regards,

      Lee

      Comment

      Working...