Possible Duplicate:
How to compare two dates to find time difference in SQL Server 2005, date manipulation
I had two datetime fields and should calculate the between them including time fields.
If the difference between them is less than 24 hours it should consider as 1 day and 24 to 48 hours as 2 days.
If you’re talking about SQL Server, DATEDIFF is what you need.
Something like:
… just substitute StartDate and EndDate for your column names, and tableName for the actual table name.
Also, you can swap out the ‘d’ character for other dateparts, say if you wanted to find the date difference in months, years etc.
* Update *
@sateesh, try and follow this. I think the issue you may be having is to do with rounding in SQL’s DATEDIFF function. The way around this is to go down to a more granular level, such as minutes instead of days. See the sample code below, and compare the outputs:
Here’s the output:
I believe Attempt 2 gives you what you need. If that doesn’t help you, then I’m afraid I just don’t understand your question.