Date/time with minutes and seconds optional?

R

Randall Parker

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
 
R

Randall Parker

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

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top