Format string as short date

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

    Format string as short date

    using c#3.5, how do I take a string which contains a data, and format it as
    a short data format like this:

    "2/5/2008 1:17:11 AM"

    and format to:

    "02/05/2008"

    Thanks.

    --
    moondaddy@newsg roup.nospam


  • Peter Duniho

    #2
    Re: Format string as short date

    On Mon, 11 Feb 2008 09:57:26 -0800, moondaddy <moondaddy@news group.nospam>
    wrote:
    using c#3.5, how do I take a string which contains a data, and format it
    as
    a short data format like this:
    >
    "2/5/2008 1:17:11 AM"
    >
    and format to:
    >
    "02/05/2008"
    Well, one way would be to use the DateTime.TryPar se() method to convert
    the string to a DateTime object, and then use the
    DateTime.ToShor tDateString() to reformat the data into the the string you
    want.

    Pete

    Comment

    • Cor Ligthert[MVP]

      #3
      Re: Format string as short date

      MoonDaddy,

      First check the globalization settings are US then just

      \\\

      var date = DateTime.Parse( "5/2/2008 1:17:11").ToSho rtDateString();

      ///



      I have done it in my globalisation settings.

      Cor

      Comment

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

        #4
        Re: Format string as short date

        Hi,

        You have to convert the string to DateTime and then use
        DateTime.ToShor tDateString();

        Take a lookat DateTime.TryPar se or Convert.ToDateT ime

        --
        Ignacio Machin
        The #1 Warehouse Management System & Direct Store Delivery Software (DSD) for QuickBooks & ERP Systems – LaceUp Solutions

        Mobile & warehouse Solutions.
        "moondaddy" <moondaddy@news group.nospamwro te in message
        news:eH%23kzcNb IHA.536@TK2MSFT NGP06.phx.gbl.. .
        using c#3.5, how do I take a string which contains a data, and format it
        as a short data format like this:
        >
        "2/5/2008 1:17:11 AM"
        >
        and format to:
        >
        "02/05/2008"
        >
        Thanks.
        >
        --
        moondaddy@newsg roup.nospam
        >

        Comment

        Working...