Results 1 to 8 of 8
  1. #1
    Marcifish is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    2

    Calculate DateDiff Excluding Weekends in SQL or UDF Run on UNTRUSTED Location

    Hello;

    I am working on a small database and need to calculate differences between dates excluding weekends. I have found a large number of posts regarding doing this with VBA functions, but I need to do it strictly in SQL (it needs to feed directly into query results on a database whose location cannot be set as trusted due to my company's network requirements/regulations).

    If anyone knows of a UDF that will perform this function without the database being stored in a trusted location, I could use that instead, but all of the UDF's I can find in the forum require a trusted location to run.



    Any help would be greatly appreciated

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    Use the weekday interval "w" in the DateDiff function. Create a new field or column using SQL

    http://beginner-sql-tutorial.com/sql...-statement.htm

    and

    http://www.techonthenet.com/access/f...e/datediff.php

    Alan

  3. #3
    Marcifish is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2011
    Posts
    2
    Excellent!

    I didn't even need to use the insert function, I was simply able to replace the "d" in my existing datediff functions in the primary query's expressions with "w." I swear, both of the books I have didn't even mention that as an option in calculated fields... I can't believe it was that easy!

    Thanks so much!

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I'm sorry but I do not see how using a "w" interval would give you workdays between two dates. It gives you weeks but not workdays. I'm willing to learn here.

  5. #5
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    Allan;
    "ww" is for week
    "w" is for weekday

    Alan

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Alan,
    I knew that and tried the "w" in the Immediate window to make sure. I believe it will tell you how many "for example Wednesdays" betweem two dates.

  7. #7
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    Allan;
    Thanks for pointing that out. I had not tested it using "w," but had used it with Day and Month. I misinterpreted. I just tested and of course you are right. My turn to learn. Thanks again.. So now I wonder how the OP solved his problem?

    Alan

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    My thoughts as well. I changed the thread to "Unsolved" since that was misleading.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 04-01-2011, 09:12 AM
  2. DateDiff Excluding Weekends
    By cs93 in forum Programming
    Replies: 1
    Last Post: 03-25-2011, 04:09 PM
  3. how to filter weekends
    By pranvera in forum Access
    Replies: 17
    Last Post: 10-19-2010, 05:10 AM
  4. Weekday excluding weekends
    By jd316632 in forum Queries
    Replies: 3
    Last Post: 05-24-2010, 02:01 PM
  5. Query DateDiff calculation excluding weekends
    By Masterfinn in forum Queries
    Replies: 3
    Last Post: 04-01-2010, 09:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums