date-arithmetic

Occurrence of a number between two specific datetime ranges in Pandas

匆匆过客 提交于 2020-01-13 07:19:50
问题 I have 2 CSV files, as below. I want a new column Difference , where... if a mobile number appears within the date range of Book_date ... App_date : Difference = difference App_date and Occur_date or NaN if it doesn't occur in that date range. I also want to filter it based on a unique category and mobile_number csv_1 Mobile_Number Book_Date App_Date 503477334 2018-10-12 2018-10-18 506002884 2018-10-12 2018-10-19 501022162 2018-10-12 2018-10-16 503487338 2018-10-13 2018-10-13 506012887 2018

Occurrence of a number between two specific datetime ranges in Pandas

筅森魡賤 提交于 2020-01-13 07:19:11
问题 I have 2 CSV files, as below. I want a new column Difference , where... if a mobile number appears within the date range of Book_date ... App_date : Difference = difference App_date and Occur_date or NaN if it doesn't occur in that date range. I also want to filter it based on a unique category and mobile_number csv_1 Mobile_Number Book_Date App_Date 503477334 2018-10-12 2018-10-18 506002884 2018-10-12 2018-10-19 501022162 2018-10-12 2018-10-16 503487338 2018-10-13 2018-10-13 506012887 2018

Convert date difference to years to calculate age in MongoDB

旧城冷巷雨未停 提交于 2020-01-13 06:43:31
问题 I am using following to calculate age in timestamp difference. db.getCollection('person').aggregate( [ { $project: { item: 1, DOB: "$personal.DOB", dateDifference: { $subtract: [ new Date(), "$personal.DOB" ] } } } ] ) I get the numeric value in dateDifference . I want to convert it to years by dividing it with (365*24*60*60*1000). But I don't know how to specify this formula in above query. I have tried the following, but it does not return any value db.getCollection('person').aggregate( [ {

Calculate difference between 2 times in hours in PHP

こ雲淡風輕ζ 提交于 2020-01-11 03:28:11
问题 I have two times - For eg- the current time - 08:24 and date is 02/01/2013 in dd/mm/yyyy format and I have another time at 13:46 and date is 31/12/2012 . So, how can I calculate the difference between the 2 times in hours using PHP. (i.e. 42.63 hours) Thanks in advance. 回答1: Convert them both to timestamp values, and then subtract to get the difference in seconds. $ts1 = strtotime(str_replace('/', '-', '02/01/2013 08:24')); $ts2 = strtotime(str_replace('/', '-', '31/12/2012 13:46')); $diff =

Get the last day of the current year as date

纵饮孤独 提交于 2020-01-03 08:05:14
问题 How can I get the last day (Dec 31) of the current year as a date using PHP? I tried the following but this doesn't work: $year = date('Y'); $yearEnd = strtotime($year . '-12-31'); What I need is a date that looks like 2014-12-31 for the current year. 回答1: PHP strtotime() uses the current date/time as a basis (so it will use this current year), and you need date() to format: $yearEnd = date('Y-m-d', strtotime('Dec 31')); //or $yearEnd = date('Y-m-d', strtotime('12/31')); 回答2: You can just

Given a date range how to calculate the number of weekends partially or wholly within that range?

天大地大妈咪最大 提交于 2020-01-01 19:36:31
问题 Given a date range how to calculate the number of weekends partially or wholly within that range? (A few definitions as requested: take 'weekend' to mean Saturday and Sunday. The date range is inclusive i.e. the end date is part of the range 'wholly or partially' means that any part of the weekend falling within the date range means the whole weekend is counted.) To simplify I imagine you only actually need to know the duration and what day of the week the initial day is... I darn well now it

Given a date range how to calculate the number of weekends partially or wholly within that range?

依然范特西╮ 提交于 2020-01-01 19:36:20
问题 Given a date range how to calculate the number of weekends partially or wholly within that range? (A few definitions as requested: take 'weekend' to mean Saturday and Sunday. The date range is inclusive i.e. the end date is part of the range 'wholly or partially' means that any part of the weekend falling within the date range means the whole weekend is counted.) To simplify I imagine you only actually need to know the duration and what day of the week the initial day is... I darn well now it

How to subtract hours from a date in Oracle so it affects the day also

醉酒当歌 提交于 2019-12-31 10:32:25
问题 I'm trying to subtract date from Oracle so it even effect the day as well. For example, if the timestamp is 01/June/2015 00 hours and if I subtract 2 hours, I want to be able to go to to 31/May/2014 22 hours. I tried to_char(sysdate-(2/11), 'MM-DD-YYYY HH24') but it only subtracts the hour; it does not touch the day itself. 回答1: Others have commented on the (incorrect) use of 2/11 to specify the desired interval. I personally however prefer writing things like that using ANSI interval

Calculate the week number (0-53) in year

空扰寡人 提交于 2019-12-30 01:55:45
问题 I have a dataset with locations and dates. I would like to calculate week of the year as number (00–53) but using Thursday as the first day of the week. The data looks like this: location <- c(a,b,a,b,a,b) date <- c("04-01-2013","26-01-2013","03-02-2013","09-02-2013","20-02-2013","03-03-2013") mydf <- data.frame(location, date) mydf I know that there is strftime function for calculating week of year but it is only possible to use Monday or Sunday as the first day of the week. Any help would

Oracle: how to add minutes to a timestamp?

99封情书 提交于 2019-12-28 01:59:11
问题 I need to add 30 minutes to values in a Oracle date column. I do this in my SELECT statement by specifying to_char(date_and_time + (.000694 * 31) which works fine most of the time. But not when the time is on the AM/PM border. For example, adding 30 minutes to 12:30 [which is PM] returns 1:00 which is AM. The answer I expect is 13:00 . What's the correct way to do this? 回答1: All of the other answers are basically right but I don't think anyone's directly answered your original question.