DateTime Problem

N

niju

Hi there
I am trying to get a single digit hour in 12-hour format with the
following code.

DateTime hr = DateTime.Now;
string hour = hr.ToString("h");

However, I get "Input string was not in a correct format" error. Please
help me to correct this problem.

Many Thanks
Niju
 
A

Andrea Zani

niju said:
Hi there
I am trying to get a single digit hour in 12-hour format with the
following code.

DateTime hr = DateTime.Now;
string hour = hr.ToString("h");

However, I get "Input string was not in a correct format" error.
Please help me to correct this problem.

string hout=hr.ToString("hh");
 
T

tom pester

Hi Niju,

How does the date that you are passing to the function? Maybe you have to
first use DateTime.Parse() to get it into a format the runtime understands
and than extract your desired format.


Let me know if it helped you or not...

Cheers,
Tom Pester
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top