date-arithmetic

Calculate days between date and today in PHP [duplicate]

为君一笑 提交于 2021-02-19 01:40:55
问题 This question already has answers here : How to calculate the difference between two dates using PHP? (34 answers) Closed 7 years ago . If I have a given date in the format yyyy-mm-dd, how can I calculate the difference in days to the current date ? I just want to check whether this date is more than one week (7 days) old compared to the current date. 回答1: date_default_timezone_set('Europe/Warsaw'); $from = strtotime('2013-11-01'); $today = time(); $difference = $today - $from; echo floor(

Group dates by week in R

此生再无相见时 提交于 2021-02-16 18:30:08
问题 I wish to label my data based on their week. This is my data: df2 <- structure(list(Order_Date = structure(c(16735, 16805, 16753, 16830, 17075, 17009, 17085, 16740, 16891, 16750, 16820, 16849, 16906, 16929, 16746, 16731, 16786, 16873, 16895, 16931), class = "Date")), .Names = "Order_Date", row.names = c(NA, -20L), class = "data.frame") and I tried to label them based on the week (0th week, 1th week and ....) and I wish to group my data by the week later And I tried this: # order by data

How to group by month including all months?

一世执手 提交于 2021-02-05 11:28:46
问题 I group my table by months SELECT TO_CHAR (created, 'YYYY-MM') AS operation, COUNT (id) FROM user_info WHERE created IS NOT NULL GROUP BY ROLLUP (TO_CHAR (created, 'YYYY-MM')) 2015-04 1 2015-06 10 2015-08 22 2015-09 8 2015-10 13 2015-12 5 2016-01 25 2016-02 37 2016-03 24 2016-04 1 2016-05 1 2016-06 2 2016-08 2 2016-09 7 2016-10 103 2016-11 5 2016-12 2 2017-04 14 2017-05 2 284 But the records don't cover all the months. I would like the output to include all the months, with the missing ones

PHP: get next date based on fixed base date

安稳与你 提交于 2021-02-05 07:44:28
问题 is there a way in PHP to get the next date(s) using a 4-week interval from a given date ? Example: My start date is Friday, Jan 03, 2014 and my interval is every 4 weeks from that date. What I am looking for is the next date (or dates, if possible) from the current date that matches this 4-week interval. In the above example this would be Friday, May 23, 2014 (then June 20, 2014, July 18, 2014 etc.). I know I can get the current date as follows: $today = date('Y-m-d'); and I could probably

PHP: Time difference (min:sec:tenths)

霸气de小男生 提交于 2021-01-27 18:00:32
问题 How can I calculate time difference when operating with minutes:seconds.tenth ? For example how can I achieve this example: 40:24.5 - 67:52.4 = -27:27.9 I was going to use this but then discovered lack of tenths: $time1 = new date('40:24.5'); $time2 = new date('67:52.4'); $interval = $time1->diff($time2); echo $interval->format('%R%%i:%s:??'); 回答1: Like you already "tried", you can use DateTime extension: function time_difference($t1, $t2) { $t1 = DateTime::createFromFormat('i:s.u', $t1, new

How to perform all possible combinations of arithmetic operations on 3 integers?

风流意气都作罢 提交于 2021-01-21 11:59:49
问题 Suppose I have three integers. I want to get a list of all possible values obtained by performing all 16 (4x4 of *, /, +, - ) operations among between them. Like if I have 3 4 1 , we should get values 1, 2, 6, 7, 8, 9, 11, 12, 13, 15 and 16. That is, res = num1 (op1) num2 (op2) num3 where operators are: ["**", "*/", "*+", "*-", "/*", "//", "/+", "/-", "+*", "+/", "++", "+-", "-*", "-/", "-+", "--"] However, the catch is that division can only be possible if x%y==0 i.e. divisor is factor of

How to perform all possible combinations of arithmetic operations on 3 integers?

a 夏天 提交于 2021-01-21 11:56:44
问题 Suppose I have three integers. I want to get a list of all possible values obtained by performing all 16 (4x4 of *, /, +, - ) operations among between them. Like if I have 3 4 1 , we should get values 1, 2, 6, 7, 8, 9, 11, 12, 13, 15 and 16. That is, res = num1 (op1) num2 (op2) num3 where operators are: ["**", "*/", "*+", "*-", "/*", "//", "/+", "/-", "+*", "+/", "++", "+-", "-*", "-/", "-+", "--"] However, the catch is that division can only be possible if x%y==0 i.e. divisor is factor of

How to sum overtime hours users spent on work

老子叫甜甜 提交于 2020-12-26 12:13:06
问题 I have two SQL Server tables employee(empid, empname) and employee_movements(empid, MoveDatetime) which I store employees actions from fingerprint by datetime, I want to count hours every employee spent after work from 03:30pm until 6:00am in the next day So if I have this data | EmpID | MoveDateTime | |-------|--------------------| | 1 | 01.01.2020 3:30pm | | 1 | 01.01.2020 5:30pm | | 1 | 01.01.2020 11:00pm | | 1 | 02.01.2020 02:30am | | 2 | 01.01.2020 4:00am | | 2 | 01.01.2020 10:15am | | 1

Oracle SQL Where clause to find date records older than 30 days

眉间皱痕 提交于 2020-11-25 07:56:55
问题 I want to find records in a (Oracle SQL) table using the creation date field where records are older than 30 days. It would be nice to find records using a operators like > but if anyone can suggest quick SQL where clause statement to find records older than 30 days that would be nice. Please suggest Oracle syntax as that is what I am using. 回答1: Use: SELECT * FROM YOUR_TABLE WHERE creation_date <= TRUNC(SYSDATE) - 30 SYSDATE returns the date & time; TRUNC resets the date to being as of

Oracle SQL Where clause to find date records older than 30 days

ぐ巨炮叔叔 提交于 2020-11-25 07:52:12
问题 I want to find records in a (Oracle SQL) table using the creation date field where records are older than 30 days. It would be nice to find records using a operators like > but if anyone can suggest quick SQL where clause statement to find records older than 30 days that would be nice. Please suggest Oracle syntax as that is what I am using. 回答1: Use: SELECT * FROM YOUR_TABLE WHERE creation_date <= TRUNC(SYSDATE) - 30 SYSDATE returns the date & time; TRUNC resets the date to being as of