We’re rewarding the question askers & reputations are being recalculated! Read more.

New answers tagged

0

No INDEX can handle that OR. Nor can any combination of indexes. UNION can help with the first 2 range tests, but it won't help with the 3rd. The 3rd range may include one-fourth of the table. Is there any limit on the time between Adding and Updating? We might be able to use a partitioning or spatial trick with that information. Barring that, I ...


0

To find the next date for given week day use this query. set the value of the week day you want in the THEDAY variable. SET @THEDAY = 1; SELECT DATE_ADD(NOW(), INTERVAL if( @THEDAY > WEEKDAY(NOW()) , (@THEDAY - WEEKDAY(NOW())) , (7 - WEEKDAY(NOW())) + @THEDAY) DAY) Note that the weekday index starts from 0 For Monday ...... 6 For Sunday


1

Your title asked for the "nth business day of the current month". And the body of your question flips that around and asks to find the "n" for the current day. I'm gonna go with the question as asked in the body. Jeff Moden has a really good write-up here. He wrote it as a function, with parameters and error handling and all of that other good stuff. But ...


4

Simple addition and subtraction. Although the code is SQL code, the math works the same in PL/SQL. This code: alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss'; with data as ( select TO_date( '13/10/2019 00:00:00', 'DD/MM/YYYY HH24:MI:SS') as foo , to_date( '01/10/1914 16:33:11', 'DD/MM/YYYY HH24:MI:SS') as bar from dual ) select ...


-3

You can use DATEPART to pull the hour/min/sec from BAR and do the same to pull day/month/year from foo, them use DATEFROMPARTS to reassemble. Pity SQL Server doesn't support the ANSI INTERVAL type, which would make this super simple.


Top 50 recent answers are included