After checking the docs, I don't thinks so, but I might have overlooked it. To meet the requirement, I was able write a function for that purpose, based on someone else's code for Oracle.

But I'd prefer a built-in solution, something like

DateDiff (workday, @startdate, @enddate).

asked 22 Oct '13, 10:00

Reimer%20Pods's gravatar image

Reimer Pods
4.2k354583
accept rate: 11%

edited 22 Oct '13, 10:31

Mark%20Culp's gravatar image

Mark Culp
23.4k9132275


There is no builtin procedure (function) to compute the number of workdays between two dates... but as you have already alluded to it is easy to write such a function. Example:

create or replace function number_of_workdays( in @date1 date, in @date2 date )
returns int
begin
  if @date1 > @date2 then
    -- swap dates so that date1 is before date2
    begin
      declare @tdate date;
      set @tdate = @date1;
      set @date1 = @date2;
      set @date2 = @tdate;
    end;
  end if;
  return datediff( day, @date1, @date2 ) + 1   -- total number of days in interval (inclusive)
         - 2*datediff( week, @date1, @date2 )  -- minus 2*number of sundays (inc d2 but not d1)
         - ( if datepart( weekday, @date2 ) = 7 then 1 else 0 endif ) -- less 1 if end on Sat.
         - ( if datepart( weekday, @date1 ) = 1 then 1 else 0 endif ) -- less 1 if start on Sun.
         ;
end;

If you are careful and don't need the date-order check in the above function then it becomes a 'one liner' which will be inlined by the SQL Anywhere execution engine.

permanent link

answered 22 Oct '13, 12:24

Mark%20Culp's gravatar image

Mark Culp
23.4k9132275
accept rate: 40%

Thanks, Mark, that looks very much like the procedure I've created.

(23 Oct '13, 08:02) Reimer Pods
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×32
×2

question asked: 22 Oct '13, 10:00

question was seen: 1,498 times

last updated: 23 Oct '13, 08:19