date-arithmetic

How do I find the time difference between two datetime objects in python?

ε祈祈猫儿з 提交于 2019-11-26 05:42:32
问题 How do I tell the time difference in minutes between two datetime objects? 回答1: >>> import datetime >>> a = datetime.datetime.now() >>> b = datetime.datetime.now() >>> c = b - a datetime.timedelta(0, 8, 562000) >>> divmod(c.days * 86400 + c.seconds, 60) (0, 8) # 0 minutes, 8 seconds 回答2: New at Python 2.7 is the timedelta instance method .total_seconds() . From the Python docs, this is equivalent to (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 . Reference: http:/

Add a month to a Date [duplicate]

时光怂恿深爱的人放手 提交于 2019-11-26 05:26:39
问题 This question already has answers here : How to subtract months from a date in R? (2 answers) Closed last year . I am trying to add a month to a date i have. But then its not possible in a straight manner so far. Following is what i tried. d <- as.Date(\"2004-01-31\") d + 60 # [1] \"2004-03-31\" Adding wont help as the month wont be overlapped. seq(as.Date(\"2004-01-31\"), by = \"month\", length = 2) # [1] \"2004-01-31\" \"2004-03-02\" Above might work , but again its not straight forward.

Calculate working hours between 2 dates in PostgreSQL

99封情书 提交于 2019-11-26 04:25:41
问题 I am developing an algorithm with Postgres (PL/pgSQL) and I need to calculate the number of working hours between 2 timestamps, taking into account that weekends are not working and the rest of the days are counted only from 8am to 15pm. Examples: From Dec 3rd at 14pm to Dec 4th at 9am should count 2 hours: 3rd = 1, 4th = 1 From Dec 3rd at 15pm to Dec 7th at 8am should count 8 hours: 3rd = 0, 4th = 8, 5th = 0, 6th = 0, 7th = 0 It would be great to consider hour fractions as well. 回答1:

Check if year is leap year in javascript [duplicate]

早过忘川 提交于 2019-11-26 03:57:14
问题 This question already has answers here : javascript to find leap year (9 answers) Closed last year . function leapYear(year){ var result; year = parseInt(document.getElementById(\"isYear\").value); if (years/400){ result = true } else if(years/100){ result = false } else if(years/4){ result= true } else{ result= false } return result } This is what I have so far (the entry is on a from thus stored in \"isYear\"), I basically followed this here, so using what I already have, how can I check if

Calculating difference in dates in Java

倾然丶 夕夏残阳落幕 提交于 2019-11-26 02:59:03
问题 I find it funny that Java (or the java.util library) does not have a built-in function to calculate difference in dates. I want to subtract one date from another to get the elapsed time between them. What is the best way to do this? I know the simple way is to take the difference of the time in milliseconds and then convert that into days. However, I wanted to know if this works in all cases (with daylight saving, etc.). 回答1: I know the simple way is to take the difference of the time in

How to find the duration of difference between two dates in java?

与世无争的帅哥 提交于 2019-11-26 00:28:22
问题 I have two objects of DateTime , which need to find the duration of their difference , I have the following code but not sure how to continue it to get to the expected results as following: Example 11/03/14 09:30:58 11/03/14 09:33:43 elapsed time is 02 minutes and 45 seconds ----------------------------------------------------- 11/03/14 09:30:58 11/03/15 09:30:58 elapsed time is a day ----------------------------------------------------- 11/03/14 09:30:58 11/03/16 09:30:58 elapsed time is two

Calculate difference between 2 date / times in Oracle SQL

那年仲夏 提交于 2019-11-26 00:24:01
问题 I have a table as follows: Filename - varchar Creation Date - Date format dd/mm/yyyy hh24:mi:ss Oldest cdr date - Date format dd/mm/yyyy hh24:mi:ss How can I calcuate the difference in hours minutes and seconds (and possibly days) between the two dates in Oracle SQL? Thanks 回答1: You can substract dates in Oracle. This will give you the difference in days. Multiply by 24 to get hours, and so on. SQL> select oldest - creation from my_table; If your date is stored as character data, you have to

Calculating days between two dates with Java [duplicate]

亡梦爱人 提交于 2019-11-25 23:13:41
问题 This question already has answers here : Calculating the difference between two Java date instances (45 answers) Closed 4 years ago . I want a Java program that calculates days between two dates. Type the first date (German notation; with whitespaces: \"dd mm yyyy\") Type the second date. The program should calculates the number of days between the two dates. How can I include leap years and summertime? My code: import java.util.Calendar; import java.util.Date; import java.util.Scanner;