.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Get Difference between two dates as Hours, Minutes

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :Sql Server


 I am using the below query to get difference beiween two dates in hours and minutes.Minutes part look ok but the hours is incorrect.

 select datediff(minute,LastDate,getdate()) as "Minutes", datediff(hour,LastDate,getdate()) as "Hours"from emp.

 Note: Using SQL Server 2005


View Complete Post

More Related Resource Links

Difference between 2 times 6:00 Hours - 5:50 hours is 10 minutes i.e 0.10 How to do the same in SSRS


Hi I have a report where I have to get the employees absence hours, i.e if there are 8 hours in a day and the employee worked for 5:50 minutes then the difference would be calculated in time.... Please also let em know how to calculate absence hours if the working ours are null as its not showing any value for absence column

WorkingHrs    HoursWorked Absencehours

8                       5.10              2.50

8                        Null              Null

I have query that I have written to get the absenceHours= WorkingHrs - HoursWorked

Please help I feel its a simple query but kinda confused with it. Thanks.


Get difference between 2 dates in minutes


I have 2 datetime columns:

Date1 = 10/1/2010 11:00:00 PM

Date2 = 10/2/2010 1:00:00 AM

I want to subtract Date 2 from Date1 and return the number of minutes difference.  Something like:

Date1 - Date2 = 120

How can I do this?




Need function to find difference between two dates


Hi all

I need a function written in vb to find the exact month difference between two dates.

For example

    Start Date : 01/01/2010

    End Date   : 15/02/2010

 then the difference value should be like this 1.5  i.e i need the difference in decimal value.

filtering by minutes and hours

guys, is there a way where i can filter my data based on the minutes and hours ie i already have the start date and end date.. i need to filter by the time as well. any help?

How to Get Total Minutes From Hours in SQL Server 2005?


Hi All.........!

I have 10:45 Hours and Now I want to get Total Minutes Like 645 Minutes.

How Can I Get in SQL Server 2005?

Please Help Me................!

Thanks in Advanced..............!

The TimeSpan could not be parsed because at least one of the hours, minutes,.....


One of my users is getting the following error:  

The TimeSpan could not be parsed because at least one of the hours, minutes, or seconds components is outside its valid range.

Here is what I have pin pointed it down to:


cmd.CommandText = "InsertExportPairing";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@pn", SqlDbType.VarChar, 50).Value = pairing.Number;
        cmd.Parameters.Add("@pt", SqlDbType.Time, 7).Value = pairing.FlightTime.Insert(2, ":");
        cmd.Parameters.Add("@date", SqlDbType.Date).Value = DateTime.ParseExact(pairing.Date, "MMM dd, yy", CultureInfo.InvariantCulture);
        cmd.Parameters.Add("@uid", SqlDbType.Int).Value = userID;
        SqlParameter outParam = cmd.Parameters.Add("@newId", SqlDbType.Int);
        outParam.Direction = ParameterDirection.Output;


How to calculate difference between two dates in years


hi all, 

i need to know if, given a birth date, a person has more than x years. Thats mean, the client must entry a date in a textbox and i need to know if the persona has more than 18 years. 

Thx in advance

How to calculate working hours betwwen two dates?


Working days - Mon-Fri and Working hours - 9 Am to 5 Pm

Date1                                       Date2                                                Working Hours

Thur, 14-Oct-10 11.30 Am          Thur, 14-Oct-10 5.00 Am                     5.30

Fri,  15-Oct-10 11.30 Am            Mon, 18-Oct-10 5.00 Am                      13.30

Mon,  18-Oct-10 11.30 Am          Mon, 18-Oct-10 6.00 Am                      5.30


Thanks & Regards, PSWA

Calculating yrs, months, days, hours, mins, seconds between two dates. SQL


I'm trying to calculate the yrs, months, days, hours, mins, seconds between two dates with sql server or c# (ive just used sql more). 

I have some code below that I started, but I get some negative values for months, values over 31 for months, and there very well could be more issues. Honestly my math is not the greatest and Im just not sure how to fix it. I want the user to be able to enter their birthday and for it to calculate the yrs, months, days, hours, mins, and seconds they have been alive.

Any help would be great 


((DATEDIFF(MONTH,'10/16/1995',GETDATE()))-(DATEDIFF(YEAR,'10/16/1995',GETDATE())*12)) AS 'Months',
(DATEDIFF(DAY,'10/16/1995',GETDATE()))-(DATEDIFF(MONTH,'10/16/1995',GETDATE())*30) AS 'Days', 
(DATEDIFF(HOUR,'10/16/1995',GETDATE()))-(DATEDIFF(DAY,'10/16/1995',GETDATE())*24) AS 'Hours',
(DATEDIFF(MINUTE,'10/16/1995',GETDATE()))-(DATEDIFF(HOUR,'10/16/1995',GETDATE())*60) AS 'Minutes',
(DATEDIFF(SECOND,'10/16/1995',GETDATE()))-(DATEDIFF(MINUTE,'10/16/1995',GETDATE())*60) AS 'Seconds'

How to calculate total work hours between dates?

I am in the process of creating a calendar.  This calendar is to track leave hours for employees.  For example if a person takes leave for 2.5 days then the formula would calculate 8hrs per day and 4 hours for half a day = 20hrs.  I have part of the formula I believe "=TEXT([End Time]-[Start Time],"h")".  The problem is that it does not count multiple days and just not working right. Any advice would help.

What is the difference between "dynamic" and "object" keywords?

Let's take a quick look at the object keyword first. I'm not going to talk a lot about it because it's been around since C# 1.0. This keyword is nothing more than a shortcut for System.Object, which is the root type in the C# class hierarchy. (However, as Eric Lippert pointed out in his blog post, not everything in C# derives from object.) This is a powerful mechanism, since you can assign almost any value to instances of this type.

.net difference between versions


 what is the difference between .net 2.0/3.0/ 3.5

Difference Btw Website vs Web application and Virtual directory in IIS 7


May i know what is the Differenc that they actually make in IIS7 .

Please tell me at a low level as i am still a novice in Asp.Net


Thanks in Advance.


Logic to calculate business hours


Hi All,

I have tried searching all over the web for this logic. Got many but half of them did not match what i was looking for and half were malfunctioning.

I want to calculate business working hours between 2 datetime, where in I should be able to set the working hours as well as weekends and holidays should not be calculated.


Please help me guys... It will be a great help... 

Difference between normal DLL & .net DLL


Hi All,

What is a difference between a regular DLL & .net DLL ?

Thanks in adavnce

difference between GetPostbackEventReference and GetCallbackEventReference



Hi All,

I was working with these two methods of ClientScriptManager class, but still not able to understand it properly.

Any one  have work on experience with these methods, want to know the difference between

GetPostbackEventReference and GetCallbackEventReference.

Friends, please dont post any urls. I also searching through different articles, but seened only definitions without any proper explained examples.

Time Difference in Linq queries


Hi All,


I have my Linq query in which i need to find time difference(not days difference).

The field in database is datetime.

Dim ldtToday As DateTime = TimeOfDay

Dim SR_RM_InnerJoin = From SR In lcntxRT60Entities.RtSReports _

Join RM In lcntxRT60Entities.RtRMaster On SR.RtRMaster.ReportID Equals RM.ReportID _

Select SR, RM _

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend