datediff

Difference between two DateTimes C#?

泄露秘密 提交于 2019-11-30 02:32:45
I need a function that can return the difference between the below two dates as 24. DateTime a = new DateTime(2008, 01, 02, 06, 30, 00); DateTime b = new DateTime(2008, 01, 03, 06, 30, 00); You can do the following: TimeSpan duration = b - a; There's plenty of built in methods in the timespan class to do what you need, i.e. duration.TotalSeconds duration.TotalMinutes More info can be found here . Try the following double hours = (b-a).TotalHours; If you just want the hour difference excluding the difference in days you can use the following int hours = (b-a).Hours; The difference between these

Difference between two dates, including only business days (i.e. excluding weekends and holidays)

五迷三道 提交于 2019-11-29 15:26:58
问题 How can I get the number of business days between two java.util.Date , i.e. excluding weekends and holidays? By holidays, I mean legally recognized holidays. It must be depending on the country, because of the holidays that are different from a country to another. For example, 2012-08-27 - 2012-08-24 should return 1 instead of 3 , because of the weekend inbetween. I already had a look on Jollyday and ObjectLab-Kit, but I can't make them meet my need. I mean, both of them have a lot of

get difference in time in HH:MM format php

心不动则不痛 提交于 2019-11-29 14:42:41
how can i get this to output HH:MM format? $to_time = strtotime("2008-12-13 10:42:00"); <--AM $from_time = strtotime("2008-12-14 8:21:00"); <-- PM $stat = round(abs($to_time - $from_time) / 60,2). "min"; what i got from this is 1299 mins but i cant figure out how to make it output 21h:41m Firstly, 8:21:00 will be interpreted as 8AM unless you specified otherwise using DateTime::createFromFormat() . To work out time differences, use DateTime::diff() : $to = new DateTime("2008-12-13 10:42:00"); $from = new DateTime("2008-12-14 8:21:00"); $stat = $to->diff($from); // DateInterval object echo

Datediff performance

笑着哭i 提交于 2019-11-29 13:49:57
问题 I have a number of days variable which I want to compare against a datetime column (senddate) . Im currently doing this : DECLARE @RunDate datetime = '2013-01-01' DECALRE @CalculationInterval int = 10 DELETE FROM TableA WHERE datediff(dd, senddate, @RunDate) > @CalculationInterval So basically anything that is older then 10 days should get deleted, we have Index on sendDate column but still the speed is much slower, I know the left side should not have calculation for performance reasons, but

SQL DateDiff advanced usage?

Deadly 提交于 2019-11-29 11:36:54
I need to calculate the DateDiff (hours) between two dates, but only during business-hours (8:30 - 16:00, no weekends). This result will then be put into the Reaction_Time column as per the example below. ID Date Reaction_Time Overdue 1 29.04.2003 15:00:00 1 30.04.2003 11:00:00 3:30 2 30.04.2003 14:00:00 2 01.05.2003 14:00:00 7:30 YES *Note: I didn't check to see if the dates in example were holidays. I'm using SQL Server 2005 This will be combined with a bigger query, but for now all I need is this to get started, I'll try to figure out how to put it all together on my own. Thanks for the

PHP Difference in months between two dates? [duplicate]

人走茶凉 提交于 2019-11-29 09:31:17
Possible Duplicate: How to calculate the difference between two dates using PHP? Date Difference in php? I have two dates in a variable like $fdate = "2011-09-01" $ldate = "2012-06-06" Now I need the difference in months between them. For example, the answer should be 10 if you calculate this from month 09 (September) to 06 (June) of next year - you'll get 10 as result. How can I do this in PHP? A more elegant solution is to use DateTime and DateInterval . <?php // @link http://www.php.net/manual/en/class.datetime.php $d1 = new DateTime('2011-09-01'); $d2 = new DateTime('2012-06-06'); // @link

SQL Server 2005: how to subtract 6 month

ⅰ亾dé卋堺 提交于 2019-11-29 09:10:27
I have a date, suppose today date declare @d datetime set @d = '20101014' I need select @d - <six month> where is the real number of days that contains last six month, beginning from @d. You can use DATEADD : select DATEADD(month, -6, @d) EDIT : if you need the number of days up to 6 months ago you can use DATEDIFF : select DATEDIFF(day, @d, DATEADD(month, -6, @d)) Also check this up (developing this theme): i need to choose the algorythm depending on the condition - if there are as many days between two dates as in 6 month (ago from the last date). I did it in this way: case when DATEDIFF(day

SSRS 2008 Datediff for Working Days

喜欢而已 提交于 2019-11-29 07:02:52
I have seen this question asked a lot and I cannot seem to find one clear answer about "how to calculate business days only between two dates?" The expression below will give me the total days but I am looking to exclude Saturday and Sunday. =DateDiff("d",Parameters!STARTDATE.Value,Parameters!ENDDATE.Value) I would appreciate specific help about how to accomplish this. Thank you in advance. Pops The SQL in the link ( Number of working days between two dates ) translated for SSRS: Hopefully this will give you a good place to start. Type this into the expression for the textbox. =(DateDiff

How to convert given number of days to years, months and days in MySQL?

时光总嘲笑我的痴心妄想 提交于 2019-11-29 04:27:28
I am trying to get the date and time duration between the Loan taken and Paid date. I used the PHP date and time functions, but it is not always accurate. How can I do this accurately in MySQL? Let assume two dates, The Loan taken date 2009-05-24 and the Loan return date 2012-04-30 I write a MySQL query SELECT DATEDIFF('2012-04-30', '2009-05-24') `total_days`; return 1072 days, which is roughly 2 Years, 11 Months, 12 Days. Please do not answer with PHP code, I already try it. Here is the code. The function below uses PHP >= 5.3 functions and convert days to years, months and days. function

SQL Server Group By Month

人走茶凉 提交于 2019-11-28 17:11:23
I have a table which has this schema ItemID UserID Year IsPaid PaymentDate Amount 1 1 2009 0 2009-11-01 300 2 1 2009 0 2009-12-01 342 3 1 2010 0 2010-01-01 243 4 1 2010 0 2010-02-01 2543 5 1 2010 0 2010-03-01 475 I'm trying to get a query working which shows the totals for each month. So far I've tried DateDiff and nested selects, but neither gives me what I want. This is the closest I have I think: DECLARE @start [datetime] = 2010/4/1; SELECT ItemID, IsPaid, (SELECT SUM(Amount) FROM Payments WHERE Year = 2010 And DateDiff(m, PaymentDate, @start) = 0 AND UserID = 100) AS "Apr", (SELECT SUM