Date time

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

    Date time

    Why i cann't convert date to DateTime :
    System.DateTime dd= Convert.ToDateT ime("27/09/2003");

    How to do that , tjis one thowes an exception .

    I can't find a Date class
  • Bret Mulvey

    #2
    Re: Date time

    Dates of that format are ambiguous. It's probably trying to parse this as
    MM/dd/yyyy. Clearly this specific date is dd/MM/yyyy but the parser doesn't
    try to figure that out. You can use DateTime.ParseE xact, e.g.

    DateTime dd = DateTime.ParseE xact("27/09/2003", "dd/MM/yyyy");

    See the documentation for DateTime.Parse to see some more flexible examples
    of how to do this without explicitly specifying the format.


    "Yosi" <yousef_kh@hotm ail.com> wrote in message
    news:11e001c385 30$025d9e00$a00 1280a@phx.gbl.. .[color=blue]
    > Why i cann't convert date to DateTime :
    > System.DateTime dd= Convert.ToDateT ime("27/09/2003");
    >
    > How to do that , tjis one thowes an exception .
    >
    > I can't find a Date class[/color]


    Comment

    • [Yosi]

      #3
      Re: Date time

      DateTime dd = DateTime.ParseE xact
      ("27/09/2003", "dd/MM/yyyy");

      I still get an error :
      "(939): No overload for method 'ParseExact' takes '2'
      arguments"

      [color=blue]
      >-----Original Message-----
      >Dates of that format are ambiguous. It's probably trying[/color]
      to parse this as[color=blue]
      >MM/dd/yyyy. Clearly this specific date is dd/MM/yyyy but[/color]
      the parser doesn't[color=blue]
      >try to figure that out. You can use DateTime.ParseE xact,[/color]
      e.g.[color=blue]
      >
      >DateTime dd = DateTime.ParseE xact[/color]
      ("27/09/2003", "dd/MM/yyyy");[color=blue]
      >
      >See the documentation for DateTime.Parse to see some[/color]
      more flexible examples[color=blue]
      >of how to do this without explicitly specifying the[/color]
      format.[color=blue]
      >
      >
      >"Yosi" <yousef_kh@hotm ail.com> wrote in message
      >news:11e001c38 530$025d9e00$a0 01280a@phx.gbl. ..[color=green]
      >> Why i cann't convert date to DateTime :
      >> System.DateTime dd= Convert.ToDateT ime("27/09/2003");
      >>
      >> How to do that , tjis one thowes an exception .
      >>
      >> I can't find a Date class[/color]
      >
      >
      >.
      >[/color]

      Comment

      Working...