Showing posts with label Linq. Show all posts
Showing posts with label Linq. Show all posts

Saturday, 30 April 2016

Use linq get HH:mm:ss or HH or mm from time data type using c# and use tostring to format datetime

Here , I was describe to get hh:mm or hh and mm format from time or TimeSpan data field using linq in c#. In below show query format to convert time to specific string format.




I will show fetching Hours(hh),Minutes(mm) in debug mode in below as:













Right mouse button click on result and click on quick watch then new windows display here to see highlighted data here as:


























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"), 
                      
                   };