Hi niju,
I found the cause of the error :
"This is actually by design. A single character is interpreted as a Standard
DataTime format, "H" & "h"
are not standard DateTime format strings. Hence those two cause exceptions.
A Custom DateTime format needs to be at least 2 characters."
This extract is taken from
http://groups.google.com/group/micro...ea90ec4c52d91a
Try this code, it should work :
DateTime hr = new DateTime(2005,5,5,15,13,1);
string hour = hr.ToString("hh");
string hourTrimmed = hr.ToString("hh").TrimStart('0');
Response.Write(hour + "<br>" + hourTrimmed);
Let me know if it helped you or not...
Cheers,
Tom Pester
Thanks Tom
I have no problem getting hour in 24-hour format with the following
code.
DateTime hr = DateTime.Now;
string hour = hr.ToString("hh");
However i cannot get a single digit hour in 12-hour format with the
following code.
DateTime hr = DateTime.Now; string hour = hr.ToString("h");