Saturday, 30 April 2016

How to get HH:mm:ss from Linq query in c#

Here, I am describing linq query to show HH:mm:ss format from datetime data field in database. In Sql Server Database table that have column name DateOfBirth and it,s type is DataTime.  The question is how can get only hours ,minute and second from date of birth.

Here, First fetch all record from database then write this code to get HH:mm:ss format only:


 var getAll = from r in PersonData 
                   
                   select new 
                  { 
                      BirthTime= r.DateOfBirth.ToString("HH:mm:ss"), 
                      
                   };
 

No comments:

Post a Comment