Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I want to get time as 01:30 format and want to compare it that if time is greater than 10:30.

I am not getting time in requested format .I am getting as 10:48:34.7553785.
Please sort out my problem.

Thanking You
Mohd Wasif
Posted
Comments
Sunasara Imdadhusen 3-Feb-11 0:18am    
In which language are you using? (C# or VB.net)
Mohd Wasif 3-Feb-11 0:30am    
C# and basically I have to compare with 10:30 in time format

You should not convert time to string to compare time. Instead, you should always compare DateTime values. Not only it does not depend on string representation, it's faster and more supportable.

—SA
 
Share this answer
 
Hi Mohad,

You can get time using following method:

C#
DateTime dt = DateTime.Now;
string HrTime12 = dt.ToString("hh:mm");//The hour, using a 12-hour clock from 01 to 12.
string HrTime24 = dt.ToString("HH:mm");//The hour, using a 24-hour clock from 00 to 23.



If you would like to see more about Date and Time format, please refer following:
Custom Date and Time Format Strings[^]

Thanks,
Imdadhusen
 
Share this answer
 
Comments
JF2015 3-Feb-11 0:24am    
Good reply. If this was not helpful, the OP should have posted more in detail whats needed. 5+
Mohd Wasif 3-Feb-11 0:28am    
The things is this I have to compare the time with 10:30 that's
u have converted it into string and I have to compare it with time format.
Sunasara Imdadhusen 3-Feb-11 0:38am    
Just add static date with variable and append time then compare it
Example
string Date = "03/02/2011 " + HrTime24;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900