Results 1 to 2 of 2

Thread: DateDiff SQLServer Problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Posts
    29
    Does anyone know how to use the DateDiff function to return the number of workdays (M-F) between two dates in SQLServer. Or is there any other function you can use. Can you write your own functions to use in views? If anyone has any ideas I would appreciate your comments.

    Thanks

  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Select DATEDIFF(day,datefield1,datefield2) will get you the number of days

    Select DATEDIFF(week,datefield1,datefield2) will get you the number of weeks

    You might be able to do something like, but it won't be precise.


    declare @numWrkDays Int
    declare @numDays Int
    declare @numWeeks int

    Select @numDays = DATEDIFF(day,datefield1,datefield2)
    Select @numWeeks=(DATEDIFF(week ,datefield1,datefield2)
    Select @numWrkdays = @numdays - (@numweeks *2)


    To answer your other questions, you could write an extended procedure in C/C++ that could be called from a script (if one doesn't already exist).

Posting Permissions

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



Click Here to Expand Forum to Full Width