date-difference

How to get date difference in minutes using Hive

风流意气都作罢 提交于 2019-12-01 03:20:37
Below query is my sql server query and I want it to convert it into hive query: select DATEDIFF([minute], '19000101', '2013-01-01 10:10:10') You could use unix_timestamp for dates after 1970 : SELECT (unix_timestamp('2013-01-01 10:10:10') - unix_timestamp('1970-01-01 00:00:00'))/60 Convert both dates to seconds from 1970-01-01 Substract them Divide by 60 to get minutes EDIT: Adding Minutes: change date to unixtime -> add var * 60sec -> convert back to date SELECT from_unixtime(unix_timestamp('2013-01-01 10:10:10') + 10 * 60) AS result db<>fiddle demo using MySQL 来源: https://stackoverflow.com

How to get date difference in minutes using Hive

倾然丶 夕夏残阳落幕 提交于 2019-11-30 23:43:12
问题 Below query is my sql server query and I want it to convert it into hive query: select DATEDIFF([minute], '19000101', '2013-01-01 10:10:10') 回答1: You could use unix_timestamp for dates after 1970 : SELECT (unix_timestamp('2013-01-01 10:10:10') - unix_timestamp('1970-01-01 00:00:00'))/60 Convert both dates to seconds from 1970-01-01 Substract them Divide by 60 to get minutes EDIT: Adding Minutes: change date to unixtime -> add var * 60sec -> convert back to date SELECT from_unixtime(unix

Oracle: Days between two date and Exclude weekdays how to handle negative numbers

早过忘川 提交于 2019-11-28 02:18:12
I have two date columns and trying to measure days between the two dates excluding weekends. I'm getting a negative number and need help solving. Table CalendarDate DayNumber FirstAssgn FirstCnt DayNumber2 Id BusinessDays 5/21/2017 Sunday 5/21/17 5/21/17 Sunday 1 -1 Query: TRUNC(TO_DATE(A.FIRST_CONTACT_DT, 'DD/MM/YYYY')) - TRUNC(TO_DATE(A.FIRST_ASSGN_DT, 'DD/MM/YYYY')) - ((((TRUNC(A.FIRST_CONTACT_DT,'D'))-(TRUNC(A.FIRST_ASSGN_DT,'D')))/7)*2) - (CASE WHEN TO_CHAR(A.FIRST_ASSGN_DT,'DY','nls_date_language=english') ='SUN' THEN 1 ELSE 0 END) - (CASE WHEN TO_CHAR(A.FIRST_CONTACT_DT,'DY','nls_date

Add column with number of days between dates in DataFrame pandas

断了今生、忘了曾经 提交于 2019-11-27 17:19:48
I want to subtract dates in 'A' from dates in 'B' and add a new column with the difference. df A B one 2014-01-01 2014-02-28 two 2014-02-03 2014-03-01 I've tried the following, but get an error when I try to include this in a for loop... import datetime date1=df['A'][0] date2=df['B'][0] mdate1 = datetime.datetime.strptime(date1, "%Y-%m-%d").date() rdate1 = datetime.datetime.strptime(date2, "%Y-%m-%d").date() delta = (mdate1 - rdate1).days print delta What should I do? Assuming these were datetime columns (if they're not apply to_datetime ) you can just subtract them: df['A'] = pd.to_datetime

Calculate Date/Time Difference in Java considering AM/PM

巧了我就是萌 提交于 2019-11-27 16:35:23
问题 I want to calculate the difference between two date/time in java using Date and Calendar classes. The format that I have is "2012-01-24 12:30:00 PM". I have implemented my own method and also google it to work with others, but haven't getting the right hint to handle AM and PM values. The date/time difference got troubled whenever the time have 12(AM/PM) in it. For example if I have date/time "2012-01-24 12:30:00 PM" and "2012-01-24 02:30:00 PM" it shows the difference is 10 hours.

Oracle: Days between two date and Exclude weekdays how to handle negative numbers

吃可爱长大的小学妹 提交于 2019-11-26 23:40:00
问题 I have two date columns and trying to measure days between the two dates excluding weekends. I'm getting a negative number and need help solving. Table CalendarDate DayNumber FirstAssgn FirstCnt DayNumber2 Id BusinessDays 5/21/2017 Sunday 5/21/17 5/21/17 Sunday 1 -1 Query: TRUNC(TO_DATE(A.FIRST_CONTACT_DT, 'DD/MM/YYYY')) - TRUNC(TO_DATE(A.FIRST_ASSGN_DT, 'DD/MM/YYYY')) - ((((TRUNC(A.FIRST_CONTACT_DT,'D'))-(TRUNC(A.FIRST_ASSGN_DT,'D')))/7)*2) - (CASE WHEN TO_CHAR(A.FIRST_ASSGN_DT,'DY','nls

Swift days between two NSDates

孤街浪徒 提交于 2019-11-26 19:54:45
I'm wondering if there is some new and awesome possibility to get the amount of days between two NSDates in Swift / the "new" Cocoa? E.g. like in Ruby I would do: (end_date - start_date).to_i Emin Buğra Saral The accepted answer won't return the correct day number between two dates. You have to consider the time difference as well. For example if you compare the dates 2015-01-01 10:00 and 2015-01-02 09:00 , days between those dates will return as 0 (zero) since the difference between those dates is less than 24 hours (it's 23 hours). If your purpose is to get the exact day number between two

Calculate days between two dates in Java 8

佐手、 提交于 2019-11-26 17:11:35
I know there are lots of questions on SO about how to get, but I want and example using new Java 8 Date api. I also know JodaTime library, but I want a work way without external libraries. Function needs to complain with these restrictions: Prevent errors from date savetime Input are two Date's objects (without time, I know localdatetime, but I need to do with date instances) syntagma If you want logical calendar days , use DAYS.between() method from java.time.temporal.ChronoUnit : LocalDate dateBefore; LocalDate dateAfter; long daysBetween = DAYS.between(dateBefore, dateAfter); If you want

Add column with number of days between dates in DataFrame pandas

落花浮王杯 提交于 2019-11-26 11:58:44
问题 I want to subtract dates in \'A\' from dates in \'B\' and add a new column with the difference. df A B one 2014-01-01 2014-02-28 two 2014-02-03 2014-03-01 I\'ve tried the following, but get an error when I try to include this in a for loop... import datetime date1=df[\'A\'][0] date2=df[\'B\'][0] mdate1 = datetime.datetime.strptime(date1, \"%Y-%m-%d\").date() rdate1 = datetime.datetime.strptime(date2, \"%Y-%m-%d\").date() delta = (mdate1 - rdate1).days print delta What should I do? 回答1: