How to find the week days between two dates using Vertica?
Hi,
I have a ticket_createddate and ticket_Resolveddate in a table. I want to know the number of working days between these two days. How can I find it?
Eg:
ticket_createddate - 01-Sep-2023 (Friday)
ticket_Resolveddate - 04-Sep-2023 (Monday)
I want the Output as 2 because Only Friday and Monday has to be counted and Sat/Sun has to be excluded.
0
Answers
Thanks much..but the example i gave is just a single record. I have thousands of records in the table. So, if i have two date columns, then how can i find the week days difference between these columns...which has plenty of records..thanks in advance..
Then, you need to create a distinct "calendar" between creation and resolution date for each ticket:
1. UNION SELECT ticket id and start date with ticket id and resolution date, to get a
limits
table2. apply the TIMESERIES to this limits table, adding the weekday counter with a CASE WHEN expression
3. join the base tickets table with the time series query, sum the week day counters, and group by the base columns of the ticket table you want in the report.
Marco is right (like as always), it's much better to implement a calendar table into your systems, those questions become much more easier to answer.
Here is a piece of code to implement a teradata-like calendar table (I've adjusted some columns).
On my system, it's very low storage cost, only 250 bytes / year / node.
You can adjust the starting and ending dates:
Once you have this table, the query to solve your question is quite simple:
Or, with the existing calendar from my preceding answer - just a complex join with the calendar:
Excellent ! it worked...thanks a ton VValdar and Marco!!!! really appreciated!!!