Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [date-math]

Use for queries that calculate dates or date ranges

0
votes
1answer
9 views

DATE_SUB with configurable value

In MySQL you can use the DATE_SUB function to get a new date based on the values passed in. For example I can use the following to get the a date of 30 days ago from when I run the function SELECT ...
3
votes
2answers
77 views

Merge Only Events that Start immediately after the Previous Event without any Gap

How can i merge only the dates occur subsequently.? (i.e, The Next Event begins immediately after the previous event completed). Here, we need to consider some other Columns also for getting the ...
2
votes
2answers
33 views

Filter Table by a Historical 'Last Day of the Month'

I have a daily appending table, that I need a formula for that would filter the table results to just the last day of any given historical month. For example: Table: DwDate Balance ...
0
votes
0answers
25 views

Indexing strategy for date range availability in SQL [duplicate]

Imagine the structure of a simple hotel booking app: hotel_chain(id, name) hotel(id, hotel_chain_id, name) room(id, hotel_id) booking(room_id, date_start, date_end) There are hotels, that belong to ...
0
votes
1answer
42 views

Converting MySQL 5.5 datetime binary to MySQL 5.6 (math problem)

I received a database "backup" of binary files (.frm and .ibd) that were copied from a MySQL 5.5 install. Unfortunately, I was unable to get these files to import into a MySQL 5.5 vm that I created. ...
0
votes
2answers
64 views

How can I use mysql to determine the Sundays for the last year?

I have a table where I'm currently aggregating ~200 rows per day of stats. These stats include things like # of users, how many people using X feature, etc. What I'd like to do is query this table ...
0
votes
2answers
26 views

Find Events between Dates

I have table with following data id start_date end_date 1 2018-01-01 2018-01-15 2 2018-01-11 2018-01-16 3 2018-01-03 2018-02-10 4 2018-01-01 2018-03-15 I want to list events based on ...
-1
votes
1answer
120 views

How do I exclude weekends (SQL) [closed]

I have different Year, Month and Day columns, And I wish to exclude weekends. How can I do so? Thank you very much!
1
vote
1answer
454 views

Split datetime records that fall between 10pm to 7am into new record [closed]

I am very new to SQL Server. I am trying to split time in time out records that fall between night shifts from a employee shifts table but I am having a difficult time doing so. Night Shift runs from ...
3
votes
3answers
1k views

How do I round time to the upper multiple of an arbitrary time interval?

Example: If the current time is 2018-05-17 22:45:30 and the desired interval is INTERVAL '5 minute', then the desired output is 2018-05-17 22:50:00. If the current time is 2018-05-17 22:45:30 and the ...
2
votes
3answers
851 views

Multiply and divide dates

I had a recent DBA.SE question that involved dates that were used as the x-axis in a graph: Interpolate dates along a line. It was centred around a road_condition table: COND_ID ROAD_ID COND_DATE ...
5
votes
4answers
409 views

Interpolate dates along a line

I have a road_condition table in Oracle 12c: create table road_condition ( cond_id number(5,0), road_id number(5,0), cond_date date, condition number(5,0) ); insert into ...
7
votes
1answer
1k views

How does date math work in SQL Server?

I often see queries written with DATEADD and DATEDIFF in the WHERE clause to define a range, flatten datetime to 0 hours, or find the last day of a month or year, but I don't understand how all the ...