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


How to get only hours from a date in asp.net.


Like as 9/29/2011 5:41:55 PM.I want only 5 hours as output.


Plz help.

Thanks

Mohd Wasif
Posted
Comments
hitech_s 29-Sep-11 8:15am    
u need hours from datetime.now ..?

 
Share this answer
 
Try as below Code.
C#
DateTime dtNow = DateTime.Now;
int hour = dtNow.Hour;
 
Share this answer
 
Hi,

I tried some code for you try this

C#
  String str="9/29/2011 5:41:55 PM";
 String[] gh=str.Split(' ');
string hrs=gh[1].Split(':')[0];


I hope my quess is right in your question
All the Best
 
Share this answer
 

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