date-arithmetic

ORACLE SQL Date range intersections

瘦欲@ 提交于 2019-12-02 20:59:33
I have a table T1, it contains a NAME value (not unique), and a date range (D1 and D2 which are dates) When NAME are the same, we make a union of the date ranges (e.g. B). But as a result (X), we need to make intersection of all the date ranges Edit: Table T1 NAME | D1 | D2 A | 20100101 | 20101211 B | 20100120 | 20100415 B | 20100510 | 20101230 C | 20100313 | 20100610 Result : X | 20100313 | 20100415 X | 20100510 | 20100610 Visually, this will give the following : NAME : date range A : [-----------------------]----- B : --[----]---------------------- B : ----------[---------------]--- C : ----

Easy way to get day number of current quarter?

▼魔方 西西 提交于 2019-12-02 19:17:31
PHP provides ways to get the number of the current day of the month (date('j')) as well as the number of the current day of the year (date('z')). Is there a way to get the number of the current day of the current quarter? So right now, August 5, it is day 36 of the third quarter. If there is no standard way of calculating this, does anyone have a (prefereably PHP-based) algorithm handy? Michiel How about: $curMonth = date("m", time()); $curQuarter = ceil($curMonth/3); I wrote a class with the following methods. Enjoy. public static function getQuarterByMonth($monthNumber) { return floor((

How can I get a date after 15 days/1 month in PHP?

喜欢而已 提交于 2019-12-02 19:03:09
In my PHP code I have a date in my variable "$postedDate". Now I want to get the date after 7 days, 15 days, one month and 2 months have elapsed. Which date function should I use? Output date format should be in US format. Use strtotime. $newDate = strtotime('+15 days',$date) $newDate will now be 15 days after $date. $date is unix time. http://uk.php.net/strtotime try this $date = date("Y-m-d");// current date $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day"); $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 week"); $date = strtotime(date("Y-m-d", strtotime($date)) . " +2

Date column arithmetic in PostgreSQL query

陌路散爱 提交于 2019-12-02 14:15:06
问题 I have two tables that look like this: CREATE TABLE table1 (user_id int, the_date date); CREATE TABLE table2 (user_id int, the_date date, something_else real); I am writing a query that looks like this CREATE TABLE foo AS SELECT t1.user_id , (t1.the_date - (t2.the_date - t1.the_date)::int) start_date FROM table1 t1, table2 t2 where t1.user_id=t2.user_id ; When I run the above query, I get the following error displayed on the psql console: ERROR: syntax error at or near "$1" LINE 1: ...the

Trouble with date substraction in Oracle

谁说胖子不能爱 提交于 2019-12-02 10:35:00
问题 i have some trouble doing dates substractions on Oracle database. I have a query: select status, id, to_char(creationdatetime,'yyyy/mm/dd hh24:mm:ss') as Creation_Time, to_char(lastmodificationdatetime,'yyyy/mm/dd hh24:mm:ss') as Last_Mod_Time, substr(lastmodificationdatetime - creationdatetime,1,30)*24 as Time_Between, --trunc((((86400*(lastmodificationdatetime - creationdatetime))/60)/60)/24) "Days", --trunc(((86400*(lastmodificationdatetime - creationdatetime))/60)/60)-24*(trunc((((86400*

Date column arithmetic in PostgreSQL query

允我心安 提交于 2019-12-02 08:23:37
I have two tables that look like this: CREATE TABLE table1 (user_id int, the_date date); CREATE TABLE table2 (user_id int, the_date date, something_else real); I am writing a query that looks like this CREATE TABLE foo AS SELECT t1.user_id , (t1.the_date - (t2.the_date - t1.the_date)::int) start_date FROM table1 t1, table2 t2 where t1.user_id=t2.user_id ; When I run the above query, I get the following error displayed on the psql console: ERROR: syntax error at or near "$1" LINE 1: ...the_date - (t2.the_date - t1.the_date)::int) $1 ... ^ The second column in the query result is to show a date

Finding upcoming birthdays with jOOQ

雨燕双飞 提交于 2019-12-02 04:50:42
问题 I'm trying to convert an existing query which looks for upcoming birthdays to use jOOQ. My original query - using MySQL, and a bit simplified - is SELECT COUNT(*) FROM people WHERE DATE_ADD(people_dob, INTERVAL YEAR(CURDATE()) - YEAR(people_dob) YEAR) BETWEEN CURDATE() and DATE_ADD( CURDATE(), INTERVAL 7 DAY) I tried to express it using jOOQ but failed. I got as close as context .selectCount() .from(PEOPLE) .where( PEOPLE_DOB.add(year(currentTimestamp()).minus(year(PEOPLE_DOB))) .between

Trouble with date substraction in Oracle

馋奶兔 提交于 2019-12-02 04:38:10
i have some trouble doing dates substractions on Oracle database. I have a query: select status, id, to_char(creationdatetime,'yyyy/mm/dd hh24:mm:ss') as Creation_Time, to_char(lastmodificationdatetime,'yyyy/mm/dd hh24:mm:ss') as Last_Mod_Time, substr(lastmodificationdatetime - creationdatetime,1,30)*24 as Time_Between, --trunc((((86400*(lastmodificationdatetime - creationdatetime))/60)/60)/24) "Days", --trunc(((86400*(lastmodificationdatetime - creationdatetime))/60)/60)-24*(trunc((((86400*(lastmodificationdatetime - creationdatetime))/60)/60)/24)) "Hrs", --trunc((86400*

Floating point arithmetic: summation versus multiplication of error

落花浮王杯 提交于 2019-12-02 02:49:16
I'm trying to understand the floating point arithmetic behind this simple example. Both codes are arithmetically equivalent in theory, but obviously a series of additions adds more error than a simple multiplication. s=0.0 for i in range(10): s += 0.1 print(s) print('%.30f' % s) 0.9999999999999999 0.999999999999999888977697537484 but: s=0.1 s *= 10 print(s) print('%.30f' % s) 1.0 1.000000000000000000000000000000 I would like to understand what is going on behind the scenes. I understand that the binary representation of the decimal 0.1 is never accurate, and that can be verified by: print(0.1)

Finding upcoming birthdays with jOOQ

流过昼夜 提交于 2019-12-02 01:32:12
I'm trying to convert an existing query which looks for upcoming birthdays to use jOOQ. My original query - using MySQL, and a bit simplified - is SELECT COUNT(*) FROM people WHERE DATE_ADD(people_dob, INTERVAL YEAR(CURDATE()) - YEAR(people_dob) YEAR) BETWEEN CURDATE() and DATE_ADD( CURDATE(), INTERVAL 7 DAY) I tried to express it using jOOQ but failed. I got as close as context .selectCount() .from(PEOPLE) .where( PEOPLE_DOB.add(year(currentTimestamp()).minus(year(PEOPLE_DOB))) .between(currentTimestamp()).and(currentTimestamp().add(7))); Unfortunately, that translates to select count(*) from