SQL
Time Difference (year, month, day, week, hour, minute, second .....)
select datediff(year,'2010-5-5',getdate())select datediff(month,'2010-5-5',getdate())select datediff(day,'2010-5-5',getdate())select datediff(week,'2010-5-5',getdate())select datediff(hour,'2010-5-5',getdate())select datediff(minute,'2010-5-5',getdate())select datediff(second,'2010-5-5',getdate())
Output:
22473710517689106136363681796
C # Medium
Datetime dt = datetime. now; datetime dt2 = convert. todatetime ("2010-4-9"); response. write ("onboarding Date:" + dt2.tostring (); response. write ("<br>"); response. write ("current date:" + dt. tostring (); response. write ("<br>"); response. write ("Year of Difference:" + (DT. year-dt2.year ). tostring (); response. write ("<br>"); response. write ("month difference:" + (DT. year-dt2.year) * 12 + dt. month-dt2.month ). tostring (); response. write ("<br>"); response. write ("date of Difference:" + dt. subtract (dt2 ). duration (). days. tostring (); response. write ("<br> ");
Output:
Employment Date: 2010/4/9 0:00:00 current date: 1:22:18 difference year: 2 difference month: 25 difference day: 763
A better way to calculate the time difference is to use the existing time functions in SQL.
Otherwise, input parameters in C # To the SQL stored procedure.
Otherwise, use datediff in VB to reference the system. VB namespace (because VB is not installed)No practice!