Results 1 to 2 of 2

Thread: TSQL : Calculating working days between two dates

  1. #1
    Jon Reade Guest

    TSQL : Calculating working days between two dates

    Hello,
    Can anyone out there tell me if there's a simple way to calculate the number of week days between two dates in TSQL? Need it to calc. average turnaround times, excluding weekends. Can do it v. easily in VB, but gets a little more tricky in TSQL as there's no way to return the number of Sundays and Saturdays between the two dates. Any help much appreciated !

    Jon Reade
    Sql Server DBA
    NEC Technologies (UK) Ltd.

  2. #2
    Duncan Maddox Guest

    TSQL : Calculating working days between two dates (reply)


    This works for me ( @d1 <= @d2 datetimes )

    SELECT 5 * DATEDIFF(ww,@d1,@d2) + DATEPART(dw,@d2) - DATEPART(dw,@d1) + 1

    However it may give slightly dodgy results if one of the days is a saturday or sunday !!!

    Duncan

    ------------
    Jon Reade at 7/12/00 4:53:39 AM

    Hello,
    Can anyone out there tell me if there&#39;s a simple way to calculate the number of week days between two dates in TSQL? Need it to calc. average turnaround times, excluding weekends. Can do it v. easily in VB, but gets a little more tricky in TSQL as there&#39;s no way to return the number of Sundays and Saturdays between the two dates. Any help much appreciated !

    Jon Reade
    Sql Server DBA
    NEC Technologies (UK) Ltd.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •