Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. DateFormat

DateFormat

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharphelptutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nagaraju_Focus
    wrote on last edited by
    #1

    Hi All, In .net,I have to convert a string into date in a format 'dd/MM/yyyy'. My Code is System::DateTime ^dt=Convert::ToDateTime(this->txtModifiedDt->Text); try { String ^str=String::Format("{0,9:dd/MM/yyyy}",dt); MessageBox::Show(str); } catch(Exception ^e1) { MessageBox::Show(e1->Message); } its working fine when I type in the order of dd/mm/yyyy format But when i type for example: 08/13/2006.it is giving error that exception has occurred. But what i need ,it should automatically convert date as 13,month as 08 . ie like 13/08/2006 Is there any way to do like that Thanks in advance Nagaraju

    J M G 3 Replies Last reply
    0
    • N Nagaraju_Focus

      Hi All, In .net,I have to convert a string into date in a format 'dd/MM/yyyy'. My Code is System::DateTime ^dt=Convert::ToDateTime(this->txtModifiedDt->Text); try { String ^str=String::Format("{0,9:dd/MM/yyyy}",dt); MessageBox::Show(str); } catch(Exception ^e1) { MessageBox::Show(e1->Message); } its working fine when I type in the order of dd/mm/yyyy format But when i type for example: 08/13/2006.it is giving error that exception has occurred. But what i need ,it should automatically convert date as 13,month as 08 . ie like 13/08/2006 Is there any way to do like that Thanks in advance Nagaraju

      J Offline
      J Offline
      John Petersen
      wrote on last edited by
      #2

      Hello Nagaraju I think there is no way to automatically do this. You could check the input manually, but you will have to choose a standard way of interpreting, because if the user enters 09/08/2006 it could be interpreted both ways. Kind Regards, John Petersen

      1 Reply Last reply
      0
      • N Nagaraju_Focus

        Hi All, In .net,I have to convert a string into date in a format 'dd/MM/yyyy'. My Code is System::DateTime ^dt=Convert::ToDateTime(this->txtModifiedDt->Text); try { String ^str=String::Format("{0,9:dd/MM/yyyy}",dt); MessageBox::Show(str); } catch(Exception ^e1) { MessageBox::Show(e1->Message); } its working fine when I type in the order of dd/mm/yyyy format But when i type for example: 08/13/2006.it is giving error that exception has occurred. But what i need ,it should automatically convert date as 13,month as 08 . ie like 13/08/2006 Is there any way to do like that Thanks in advance Nagaraju

        M Offline
        M Offline
        Mike Dimmick
        wrote on last edited by
        #3

        Use DateTime::Parse or DateTime::TryParse in .NET 2.0 to get more control than Convert::ToDateTime offers.

        Stability. What an interesting concept. -- Chris Maunder

        1 Reply Last reply
        0
        • N Nagaraju_Focus

          Hi All, In .net,I have to convert a string into date in a format 'dd/MM/yyyy'. My Code is System::DateTime ^dt=Convert::ToDateTime(this->txtModifiedDt->Text); try { String ^str=String::Format("{0,9:dd/MM/yyyy}",dt); MessageBox::Show(str); } catch(Exception ^e1) { MessageBox::Show(e1->Message); } its working fine when I type in the order of dd/mm/yyyy format But when i type for example: 08/13/2006.it is giving error that exception has occurred. But what i need ,it should automatically convert date as 13,month as 08 . ie like 13/08/2006 Is there any way to do like that Thanks in advance Nagaraju

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Use the DateTime.ParseExact method to specify the format that you are accepting.

          --- b { font-weight: normal; }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups