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

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

find Hours Between Two Date

Posted By:      Posted Date: September 22, 2010    Points: 0   Category :Sql Server
I Have two columns in my database datatype is datetime, now i want to find the difference in hours between two dates.

View Complete Post

More Related Resource Links

how to find local time and date usin gmt time and ofset value

Hi All, i have to calculate local time and date in our data base i have gmt time range from 00:00 to 23:59 and offset is in same range but with + an - sign when + then we have to substract and when - then we have add and adjest the date with the given time for eg  gmt id 23:30 and ofset is +2:30 and date is '28-08-2010' then my local time is 23:30 -2:30  =21:00 and date will not change i want a cricteria like when offset get added then value should not be like 22:60 insted of this it is 23:00 and if it is exiding 24 then date should be increase and if time is - after gmt+ofset then date should be redused   Please give me a idea so i can solve it.  

Expression for 24 hours time and date in SSRS

Hi Guys, What is the expression for  displaying 24 hours time and date in SSRS? Is this the format: =Format(now, "MM/dd/yyyy HH:mm:ss")?Thanks Shiven:)

MOSS 2007 Calculate Due Date including working hours and working days

Hi, I've searched many forums for an answer to my problem but with very limited success. Basically, I've created a Sharepoint list where I would like to track a resolution of incidents versus SLA timings. I have a column with a receiving date, which is a date when the request was submitted and another column with priority code where I have 3 possible values: low (5 working days to close the request), medium (3 days) and high (1 day). What I would like to do is to automatically calculate due date for solving the incident based on the receiving date and the priority code. The thing is that now it is getting more complicated since I need to exclude saturdays and sundays from calculation, as well as national holidays. Then I would like to take into account working hours (from 8am to 4pm), for example if an incident with medium priority was submitted on Friday 5pm, then it would have its due date set to Wednesday 4pm (the request was sent after working hours so we have 3 full working days to complete it) Not sure if it is feasible to achieve using formulas, maybe some other way?

Find date of minumum score


I am trying to find the date when a person had their lowest score. I have tried something like this and it fails everytime that there are muliple answers:



select (updated_date) from person_detail where



want to display 24 hours time and date with datatype Datetime (Not String) in SSRS


Hi All,

I want to display 24 hours time and date in SSRS & for that I am using Format(now,"MM/dd/yyyy HH:mm:ss") but I am using this expression in Parameter, where I need to define datatype of that parameter as DateTime, not string. For Expression Format(now,"MM/dd/yyyy HH:mm:ss"), If I use DateTime datatype, It is showing error but working with String datatype.

For example:

I have parameter To Date  and value of this parameter should be 10/11/2010 13:09:16 (To Date: 10/11/2010 23:09:16) , not in AP or PM format and datatype of this parameter, want to keep DateTime that I can select value from Calender.

Please suggest me how I can achieve this?. I don't want to do it in stored Procedure side, want to do it in report side.

Thanks Shiven:)

MDX - Find last leaf member of Date dimension under selected member of Date dimension, independently


Hi all

I need to reproduce the behaviour of the averageofchildren function with the exception that the function should always build the average of all members (even when the value of a member equals null). As you know average of children function always build the average at the lowest level of the time dimension.

My date dimension looks like the following:

[Date].[Fiscal] user defined hierarchy:




if context of [Date].[Fiscal].CurrentMember corresponds to a Week, I can retrieve all weeks before the current week using

In Period: MTD([Date].[Fiscal].CurrentMember)  -- PeriodsToDate also works fine

In Year: YTD([Date].[Fiscal].CurrentMember)

if context of [Date].[Fiscal].CurrentMember corresponds to a Period

How can I get all weeks (NOT Periods!) contained in all Periods before and within current period since start of year?

What would be a generic expression that retrieves all weeks before and in independently of level of selected Date dimension member




find last pay date where non zero wgt


I have payment records that are in my table and need to update that table with the lastest pay date(non zero wgt) for all billnbrs that match.

I have billnbr,invnbr,line,payment,wgt,paydate fields defined in table. The payments with zero wgt are the ones needing updated they are like a surcharge but need to show the actual paydate for the entire billnbr.


  What I would like to do is make the paydate for each billnbr(group by) reflect the true final payment which is the non zero wgt record. The table would look like this after update step.







Find the nearest date before Saturday, Sunday and holidays with Linq


 var tecaji = (from xml in doc.Descendants(slazhnmaespace + "tecajnica")
                      where xml.Attribute("datum").Value == "2010-10-158"
                      select xml).Elements().Where(a => a.Attribute("oznaka").Value.Equals("TRY")).Select(n => n.Value).SingleOrDefault();

I have dates that are not in the XML file, but value still has to show.

In the table there is no value for the date of 23.10.2010, 24.20.2010. How do you show value for the date 10/22/2010?

Finding the appropriate date, which is najbluzjemu to that in the table.

In this XML table is not displayed dates (Saturday - Sunday).

Therefore, to find the nearest date before Saturday and Sunday.

If it is Saturday, the date "02.10.2010" shall be the date of "01/10/2010.

How do I get to that solution?


how to find date


I want to write select query ,the requirement is I have to find out date which is 3 days less than twenty fifth days of prior month

it start from 2010 .

Do you guys know it is possible to write select query ,I am writing query but not getting expected result .I am trying to do this in excel sheet also by writing excel program . please let me know.Thanks

Find date accordung to the condition


hi All,

I have Start date and accordingly find out end date

eg.if startdate=1/1/2010 then enddate=1/2/2010 for this use 


NOw if startdate = 28/2/2010 the output shuold be 31/3/2010.how to do this?

Here enddate=startdate.AddMonths(1) gives o/p=28/3/2010  but i want o/p shuold 31/3/2010.

Thanks in advance.


INFOPATH: how can I calculate hours between 2 date fields in a list form


I am trying to calculate the number of hours between 2 date/time fields in a list form.

If I do this on a list view level with a calculated column, the column is not available for column summaries. Therefor I intend to use a regular number column and calculate the hours in an InfoPath form. Obviously the formula for calculated fields in list columns will not work in InfoPath.

Addition: I tried DateField1-DateField2, but the result is NaN...




Using a CompareValidator to check input is a valid date

The CompareValidator can do more than just compare two controls. You can also compare it against several of the main .net data types such as Date, Integer, Double and Currency.

To do this you would set Operator="DataTypeCheck" and instead of setting the ControlToCompare or ValueToCompare attributes as you normally would you use the Type="Date" (or any of the data types I have listed above).

How To Set a Date Format In GridView Using ASP.NET 2.0

A very common desire is to set a column of a gridview to display just the month, day and year of a DateTime type. The problem is the by default, the HtmlEncode property of the boundfield attribute (
The problem is that if this field is enabled, you can not pass format information to the boundfield control. That is, if you try the following code, you will not get the desired result.

jQuery Date picker Implementation in ASP.NET

I've posted a wrapper ASP.NET around the jQuery.UI Datepickercontrol. This small client side calendar control is compact, looks nice and is very easy to use and I've added it some time back to my control library.

This is primarily an update for the jQuery.ui version, and so I spend a few hours or so cleaning it up which wasn't as easy as it could have been since the API has changed quite drastically from Marc's original implementation. The biggest changes have to do with the theming integration and the resulting explosion of related resources.

If you want to use this component you can check it out a sample and the code here:

How to format datetime & date with century?

Execute the following Microsoft SQL Server T-SQL datetime, date and time formatting scripts in Management Studio Query Editor to demonstrate the usage of the multitude of temporal data formats available and the application of date / datetime functions.


Date and Time Functions in SQLSERVER

Date and time functions allow you to manipulate columns and variables with DATETIME and SMALLDATETIME data types.

1 DATEPART Function
2 DATENAME Function
3 DAY, MONTH, and YEAR Functions
5 DATEADD Functions
6 DATEDIFF Function
7 More SQL Server Functions

Data Types - Date and Time in SqlServer

Date and time values can be stored with either the DATETIME or SMALLDATETIME data type. The difference between the two is that SMALLDATETIME supports a smaller range of dates and does not give the same level of precision when accounting for time. The DATETIME data type can hold values from January 1st of 1753 to December 31st of 9999. The time is stored to the 1 three hundredths of a second and each value takes up 8 bytes of storage. The SMALLDATETIME data type can hold values between January 1st 1900 and June 6th of 2079. The time is tracked to the minute and each value takes up 4 bytes of storage. The majority of business applications can live happily with SMALLDATETIME, however, if you are in an environment where each second matters or you need to make estimates to the distant future (or past) then you have to resort to DATETIME. If you fail to specify the time when inserting a value into a DATETIME or SMALLDATETIME column, a default of midnight is used. If you fail to specify the date portion the default of January 1, 1900 is used.
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