datediff

Count the months between two dates in a data.table

喜夏-厌秋 提交于 2020-07-19 18:24:31
问题 I have a data.table like the following: ID start_date end_date 1 2015.01.01 2016.02.01 2 2015.06.01 2016.03.01 3 2016.01.01 2017.01.01 I would like to get the following: ID start_date end_date Months_passed 1 2015.01.01 2016.02.01 13 2 2015.06.01 2016.03.01 9 3 2016.01.01 2017.01.01 12 I was trying the following code: DT[, Months_passed:= length(seq(from = start_date, to = end_date, by='month')) - 1] but I get the error, that "Error in seq.Date(from = start_date, to = end_date, by = "month")

python: difference of two timedate strings

有些话、适合烂在心里 提交于 2020-06-26 04:05:11
问题 I have two date strings (taken from user input and can vary greatly) s1 = '2011:10:01:10:30:00' s2 = '2011:10:01:11:15:00' I wish to find the difference between the two as minutes. How should I proceed to tackle this ? 回答1: import datetime d1 = datetime.datetime.strptime('2011:10:01:10:30:00', '%Y:%m:%d:%H:%M:%S') d2 = datetime.datetime.strptime('2011:10:01:11:15:00', '%Y:%m:%d:%H:%M:%S') diff = (d2 - d1).total_seconds() / 60 If you need to handle arbitrary datetime formats, I don't believe

How to calculate DATE Difference in PostgreSQL?

拜拜、爱过 提交于 2020-05-24 17:57:00
问题 Here I need to calculate the difference of the two dates in the PostgreSQL . In SQL Server : Like we do in SQL Server its much easier. DATEDIFF(Day, MIN(joindate), MAX(joindate)) AS DateDifference; My Try : I am trying using the following script: (Max(joindate) - Min(joindate)) as DateDifference; Question : Is my method correct? Is there any function in PostgreSQL to calculate this? 回答1: Your calculation is correct for DATE types, but if your values are timestamps, you should probably use

How to calculate DATE Difference in PostgreSQL?

折月煮酒 提交于 2020-05-24 17:55:48
问题 Here I need to calculate the difference of the two dates in the PostgreSQL . In SQL Server : Like we do in SQL Server its much easier. DATEDIFF(Day, MIN(joindate), MAX(joindate)) AS DateDifference; My Try : I am trying using the following script: (Max(joindate) - Min(joindate)) as DateDifference; Question : Is my method correct? Is there any function in PostgreSQL to calculate this? 回答1: Your calculation is correct for DATE types, but if your values are timestamps, you should probably use

Have DateDiff Show Decimals

泪湿孤枕 提交于 2020-02-05 14:18:53
问题 I am using the DateDiff function, but I would like for it to give me 3 decimal places. How should my query be altered to achieve such result? -- I need this done via the query itself not a VBA function. Date123: DateDiff('d', [startdate], [enddate]) 回答1: For a line that you can just put into a query, I'd use something like the following. Format(DateDiff("s",[DateOne],[DateTwo])/60/60/24,"#.###") Better practice would be to create a function in a module in your db like the following. Then call

Have DateDiff Show Decimals

点点圈 提交于 2020-02-05 14:16:57
问题 I am using the DateDiff function, but I would like for it to give me 3 decimal places. How should my query be altered to achieve such result? -- I need this done via the query itself not a VBA function. Date123: DateDiff('d', [startdate], [enddate]) 回答1: For a line that you can just put into a query, I'd use something like the following. Format(DateDiff("s",[DateOne],[DateTwo])/60/60/24,"#.###") Better practice would be to create a function in a module in your db like the following. Then call

Have DateDiff Show Decimals

三世轮回 提交于 2020-02-05 14:16:44
问题 I am using the DateDiff function, but I would like for it to give me 3 decimal places. How should my query be altered to achieve such result? -- I need this done via the query itself not a VBA function. Date123: DateDiff('d', [startdate], [enddate]) 回答1: For a line that you can just put into a query, I'd use something like the following. Format(DateDiff("s",[DateOne],[DateTwo])/60/60/24,"#.###") Better practice would be to create a function in a module in your db like the following. Then call

How to use DATEDIFF? How many days are inside of two dates

懵懂的女人 提交于 2020-02-05 05:14:28
问题 How to use DATEDIFF? How can I make this to work? or should I use DATEDIFF completly differently? SELECT DATEDIFF('Started ','will_end') AS 'Duration' FROM my_table WHERE id = '110'; I try to get answer, how many days are inside of two dates. I would like to get an aswer like: Duration = 7 days; I have this kind of database: Started | will_end 2009-12-17 | 2009-12-24 2009-12-12 | 2009-12-26 回答1: Put will_end first, started second: SELECT DATEDIFF('2009-12-24', '2009-12-17') --- 7 Also, remove

Undefined date_diff()

若如初见. 提交于 2020-02-01 03:35:46
问题 I'm trying to use date_diff() : $datetime1 = date_create('19.03.2010'); $datetime2 = date_create('22.04.2010'); $interval = date_diff($datetime1, $datetime2); echo $interval->format('%R%d days'); Its doesn't work for me, gives an error: Call to undefined function date_diff() How can I get it work? PHP 5.2 is used. Thanks. 回答1: The function date_diff requires a PHP version of 5.3 or greater. UPDATE An example for PHP 5.2 (taken from the date_diff user comments). <?php function date_diff($date1

Mysql: Calculate averge time between visits

谁说我不能喝 提交于 2020-01-25 04:44:06
问题 This related to my other question. I have this table CREATE OR REPLACE TABLE hits (ip bigint, page VARCHAR(256), agent VARCHAR(1000), date datetime) and I want to calculate average time between googlebot visit for every page. ... WHERE agent like '%Googlebot%' group by page order by date Something like select datediff('2010-09-18 04:20:47', '2010-09-16 05:23:04') but for every date in table If there is no mysql way, how can I do this in php? 回答1: SELECT page, TIMESTAMPDIFF(SECOND, MIN(date),