insert only time in sql server database

It is not possible to insert standalone Time into SQL database but you can take only Time from user inputs like textbox
and parse it to DateTime format caution but the provided input must be in proper format like HH:MM:SS, HH:MM note along with
input time you will get current date automatically. Now you can insert provided time into database and retrive it for calcualtion
using diffenent date methods on it.

code example

string date = "12:15 PM";
DateTime datevalue = DateTime.Parse(date); 
Labelcheck.Text = datevalue.ToString();

output

showing difference between two Time when retrieving from database using linq


  var grandTotalWork = (from t in db.AssignmentHandymandetails join ad in   
                    db.AssignmentDetails on t.assignment_detail_id equals ad.assignment_detail_id where ad.assignment_id ==    Convert.ToInt32(Label_assignmentId.Text)  
                   select new { startTime = t.started_time.Value.TimeOfDay, endTime = t.end_time.Value.TimeOfDay,  
                  TotalWorkTime = (t.started_time.Value.TimeOfDay.Duration() - t.end_time.Value.TimeOfDay.Duration()).Duration()});  

No comments:

Post a Comment