Date/time with minutes and seconds optional?

Discussion in 'ASP .Net' started by Randall Parker, Dec 8, 2005.

  1. I'm using this:
    MyDateTimeStr = MyDateTimeVal.ToString("MM-dd-yyyy hh:mm:ss tt");
    in C# to convert what I read from a form submit.

    What I want is something more flexible where the minutes and seconds are optional.
    How to do that?

    I want to able to specify several variations as all legal:

    6-30-2005 4pm
    6-30-2005 4 pm
    6-30-2005 4:30 pm
    6-30-2005 4:30:15 pm
    6-30-2005 4:30:15 p
    6-30-05 4:30:15 pm

    And similarly with slashes:

    6/30/2005 4:30:15 pm
    Randall Parker, Dec 8, 2005
    #1
    1. Advertising

  2. oops, copied the wrong line. This is what I'm using:

    DateTime LastServiceDateTimeVal = DateTime.ParseExact(InputString,
    "MM-dd-yyyy hh:mm:ss tt",null);




    Randall Parker wrote:
    > I'm using this:
    > MyDateTimeStr = MyDateTimeVal.ToString("MM-dd-yyyy hh:mm:ss tt");
    > in C# to convert what I read from a form submit.
    >
    > What I want is something more flexible where the minutes and seconds are
    > optional. How to do that?
    >
    > I want to able to specify several variations as all legal:
    >
    > 6-30-2005 4pm
    > 6-30-2005 4 pm
    > 6-30-2005 4:30 pm
    > 6-30-2005 4:30:15 pm
    > 6-30-2005 4:30:15 p
    > 6-30-05 4:30:15 pm
    >
    > And similarly with slashes:
    >
    > 6/30/2005 4:30:15 pm
    Randall Parker, Dec 8, 2005
    #2
    1. Advertising

  3. Randall Parker

    clintonG Guest

    Here's a lead [1] to a document. Use the formatters to return your desired
    results.

    <%= Clinton Gallagher
    METROmilwaukee (sm) "A Regional Information Service"
    NET csgallagher AT metromilwaukee.com
    URL http://metromilwaukee.com/
    URL http://clintongallagher.metromilwaukee.com/

    [1]
    http://www.codeguru.com/Csharp/Csharp/cs_date_time/formatting/article.php/c4205/


    "Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit.com>
    wrote in message news:eQmxdJ8%...
    > oops, copied the wrong line. This is what I'm using:
    >
    > DateTime LastServiceDateTimeVal = DateTime.ParseExact(InputString,
    > "MM-dd-yyyy hh:mm:ss tt",null);
    >
    >
    >
    >
    > Randall Parker wrote:
    >> I'm using this:
    >> MyDateTimeStr = MyDateTimeVal.ToString("MM-dd-yyyy hh:mm:ss tt");
    >> in C# to convert what I read from a form submit.
    >>
    >> What I want is something more flexible where the minutes and seconds are
    >> optional. How to do that?
    >>
    >> I want to able to specify several variations as all legal:
    >>
    >> 6-30-2005 4pm
    >> 6-30-2005 4 pm
    >> 6-30-2005 4:30 pm
    >> 6-30-2005 4:30:15 pm
    >> 6-30-2005 4:30:15 p
    >> 6-30-05 4:30:15 pm
    >>
    >> And similarly with slashes:
    >>
    >> 6/30/2005 4:30:15 pm
    clintonG, Dec 8, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    7
    Views:
    16,950
    tshad
    Mar 11, 2005
  2. 00_CP_D12
    Replies:
    3
    Views:
    8,895
    dilipv
    Feb 22, 2008
  3. Stu
    Replies:
    7
    Views:
    1,747
    Dave Thompson
    Mar 7, 2005
  4. Michael Tan
    Replies:
    32
    Views:
    956
    Ara.T.Howard
    Jul 21, 2005
  5. `p
    Replies:
    7
    Views:
    365
    Steve Litt
    Dec 14, 2005
Loading...

Share This Page