change the date format dd/mm/yyyy to m/d/yy

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

    change the date format dd/mm/yyyy to m/d/yy



    Hi

    Is there a way to change a date format dd/mm/yyyy to m/d/yy?

    I have a textBox where the user should put a date, but no matter what
    format the user input dd/mm/yyyy or m/d/yy, I need to convert it to
    this format: m/d/yy.


    Cheers!

    Claudi

    *** Sent via Developersdex http://www.developersdex.com ***
  • Dan Bass

    #2
    Re: change the date format dd/mm/yyyy to m/d/yy


    how do you know whether they mean "dd mm yyyy" or "mm dd yyyy"? On friday it
    will be the 1st of the 7th, but also the 07 / 01 according to the US.
    Resolving date ambiguity is something many people miss...
    This problem could be solved, for example, with drop downs stating "Day[ ]
    Month[ ] Year[ ]" which contain values you populate so that the user has no
    choice. The other way would be to have a readonly text box and for the user
    to choose the date through a calendar control.

    DateTime.ParseS tring() (i think it is) will take in your string and convert
    it to a DateTime object, from there you can do what you want with it, then
    set it back to a string by
    myDateTimeObjec t.ToString ("dd/mm/yyyy" );

    Good luck.

    Dan.

    "Claudia Fong" <cdolphin88@yah oo.co.uk> wrote in message
    news:%237nstW8e FHA.3048@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    >
    >
    > Hi
    >
    > Is there a way to change a date format dd/mm/yyyy to m/d/yy?
    >
    > I have a textBox where the user should put a date, but no matter what
    > format the user input dd/mm/yyyy or m/d/yy, I need to convert it to
    > this format: m/d/yy.
    >
    >
    > Cheers!
    >
    > Claudi
    >
    > *** Sent via Developersdex http://www.developersdex.com ***[/color]


    Comment

    • Ignacio Machin \( .NET/ C# MVP \)

      #3
      Re: change the date format dd/mm/yyyy to m/d/yy

      Hi,

      Then you have two problems:
      1- First you have to check the Text entered and decide in which format it's
      written and also of course if it;s valid in either one.
      solution: Use a regular expression for this.
      2- Using DateTime.ParseE xact like this:
      DateTime.ParseE xact ( textbox1.Text, "M/d/yy" ,
      DateTimeFormatI nfo.InvariantIn fo );


      Cheers,

      --
      Ignacio Machin,
      ignacio.machin AT dot.state.fl.us
      Florida Department Of Transportation




      "Claudia Fong" <cdolphin88@yah oo.co.uk> wrote in message
      news:%237nstW8e FHA.3048@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      >
      >
      > Hi
      >
      > Is there a way to change a date format dd/mm/yyyy to m/d/yy?
      >
      > I have a textBox where the user should put a date, but no matter what
      > format the user input dd/mm/yyyy or m/d/yy, I need to convert it to
      > this format: m/d/yy.
      >
      >
      > Cheers!
      >
      > Claudi
      >
      > *** Sent via Developersdex http://www.developersdex.com ***[/color]


      Comment

      • Ignacio Machin \( .NET/ C# MVP \)

        #4
        Re: change the date format dd/mm/yyyy to m/d/yy

        hi,

        well in the case of the OP he can decide based on the year, as both months
        and days may be two digits, I forgot to mention it in the response I just
        sent.

        I do concord with you 100% that the ambiguity is a problem, particularly in
        this case.


        cheers,

        --
        Ignacio Machin,
        ignacio.machin AT dot.state.fl.us
        Florida Department Of Transportation



        "Dan Bass" <Not Listed> wrote in message
        news:%236MQE18e FHA.3504@TK2MSF TNGP14.phx.gbl. ..[color=blue]
        >
        > how do you know whether they mean "dd mm yyyy" or "mm dd yyyy"? On friday
        > it will be the 1st of the 7th, but also the 07 / 01 according to the US.
        > Resolving date ambiguity is something many people miss...
        > This problem could be solved, for example, with drop downs stating "Day[ ]
        > Month[ ] Year[ ]" which contain values you populate so that the user has
        > no choice. The other way would be to have a readonly text box and for the
        > user to choose the date through a calendar control.
        >
        > DateTime.ParseS tring() (i think it is) will take in your string and
        > convert it to a DateTime object, from there you can do what you want with
        > it, then set it back to a string by
        > myDateTimeObjec t.ToString ("dd/mm/yyyy" );
        >
        > Good luck.
        >
        > Dan.
        >
        > "Claudia Fong" <cdolphin88@yah oo.co.uk> wrote in message
        > news:%237nstW8e FHA.3048@TK2MSF TNGP12.phx.gbl. ..[color=green]
        >>
        >>
        >> Hi
        >>
        >> Is there a way to change a date format dd/mm/yyyy to m/d/yy?
        >>
        >> I have a textBox where the user should put a date, but no matter what
        >> format the user input dd/mm/yyyy or m/d/yy, I need to convert it to
        >> this format: m/d/yy.
        >>
        >>
        >> Cheers!
        >>
        >> Claudi
        >>
        >> *** Sent via Developersdex http://www.developersdex.com ***[/color]
        >
        >[/color]


        Comment

        • Chris Dunaway

          #5
          Re: change the date format dd/mm/yyyy to m/d/yy

          Rather than use a textbox, why not use a DateTime Picker control? That
          way it eliminates the ambiguity and you can take the selected date and
          convert to any format you need using the .ToString method.

          Comment

          Working...