Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2011
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question How to not included weekends when using datediff?

    Hello,

    I am using datediff to count absence days, but I would like for it to not include sat and sun in the count. I've seen examples of this done in SQL but not in ASP is it possible to do?

    sql = "SELECT * FROM Abscence WHERE AB_Staff_ID ="&Request.Querystring("ID")&" AND YEAR(AB_Start_Date) >= Year(CURDATE())"
    set ABDB = doquery(sql)
    daycount = 0
    Do while NOT ABDB.eof
    daycount = daycount + DateDiff("d",ABDB("AB_Start_Date"),ABDB("AB_End_Date"))
    daycount=daycount+1
    ABDB.movenext
    Loop

    Thanks in advance

    Alex

  2. #2
    Regular Coder
    Join Date
    Sep 2014
    Posts
    223
    Thanks
    0
    Thanked 38 Times in 36 Posts
    Untested

    Code:
    Do while NOT ABDB.eof
       dim date1 = ABDB("AB_Start_Date")
       dim date2 = ABDB("AB_End_Date")
       dim diff = datediff("d",date1,date2)
       do while not (diff < 0)
           dim wd = weekday(date1,1)
           if not (wd = 1) and not (wd = 7) then
              daycount = daycount + 1;
           end if;
           date1 = dateadd("d",1,date1);
           diff = diff - 1
       loop
       ABDB.movenext
    loop
    I can't think of a better way as you also must check for holidays. In a delphi project I did a long time ago, the holidays are kept in the database, the loop that checks if the day is either sunday or holiday, also checks for holidays.
    Last edited by josephm; 11-17-2017 at 04:06 AM.


 

Tags for this Thread

Posting Permissions

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