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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    date picker - making the first date five days away

    Hi,

    I would like to modify this so that the first available date that can be selected is five BUSINESS days out. The script only shows Mon-Fri so if the date is Tue Jul 13, 2004, Tue Jul 20, 2004 needs to be displayed. I've reached an impasse. :(

    Ash

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    <head>
    	<title>Untitled</title>
    </head>
    
    <body>
    
    <%
    
    dateDropDown "datepicker1", 30, "DropDate"
    
    Sub DateDropDown(name, size, default1) 
        'size = the number of days to display in the drop down
        'default1 = default date selected in m-d-yyyy format (any non-date string is considered the current date)
        'skip = if set then the program will skip Sundays and Saturdays
        dim skip,today,dow,selected,option1,value,theday,mo,yr  ,dd
        skip = true
        today = Date()
        if not isdate(default1) then 'set default to current date
            default1=month(today) & "-" & day(today) & "-" & year(today)
        end if
        response.write "<select name=" & name & " style=""font-family: monospace;"">" & vbCrLf
        for i = 0 to size
            theday = dateserial(Year(today),Month(today),Day(today)+i) 'automatically adjusts to correct date
            dow = weekday(theday)
            mo = month(theday)
            yr = year(theday)
            dd = day(theday)
            option1 = weekdayname(dow,true) & " " & monthname(mo,true) & " " & dd & ", " & yr
            value = mo & "-" & dd & "-" & yr
            if dow=vbSunday then
                response.write "<option>&nbsp;</option>" & vbCrLf
            end if
            if value=default1 then
                selected=" selected"
            else 
                selected=""
            end if
            if ((dow<>vbsunday and dow<>vbsaturday) or not skip) then
                response.write "<option value=""" & value & """" & selected & ">" & option1 & "</option>" & vbCrLf
            end if
        next
        response.write "</select>"
    End Sub
    
    %>
    
    </body>
    </html>
    Last edited by AshleyQuick; 07-13-2004 at 07:48 PM.

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    you will need to use the datediff and AddDate Functions,,
    try a google search.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As I mentioned, I've reached an impasse. I have searched google and found similar functions but I'm at a loss on implementing them.

    Ashley

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Do you mean you want the next 5 business days of the current date to be the first item in the dropdown list?
    Code:
    <%
    
    dateDropDown "datepicker1", 30, 5
    
    Sub DateDropDown(name, size, businessDays) 
        'size = the number of days to display in the drop down
        'businessDays = number of business days to jump to
        'skip = if set then the program will skip Sundays and Saturdays
        dim skip,startDate,dow,selected,option1,value,theday,mo,yr,dd
        skip = true
        startDate = addBusinessDays(Date(), businessDays)
        response.write "<select name=" & name & " style=""font-family: monospace;"">" & vbCrLf
        for i = 0 to size
            theday = dateserial(Year(startDate), Month(startDate), Day(startDate)+i) 'automatically adjusts to correct date
            dow = weekday(theday)
            mo = month(theday)
            yr = year(theday)
            dd = day(theday)
            option1 = weekdayname(dow,true) & " " & monthname(mo,true) & " " & dd & ", " & yr
            value = mo & "-" & dd & "-" & yr
            if dow=vbSunday then
                response.write "<option>&nbsp;</option>" & vbCrLf
            end if
            if ((dow<>vbsunday and dow<>vbsaturday) or not skip) then
                response.write "<option value=""" & value & """>" & option1 & "</option>" & vbCrLf
            end if
        next
        response.write "</select>"
    End Sub
    
    Function addBusinessDays(byval dt, byval num)
      dim ctr
      ctr=0
      do
        if (weekday(dt)<=vbthursday) then
          dt = dateadd("D",1,dt) 
        else  'friday, skip weekend
          dt = dateadd("D",3,dt) 
        end if
        ctr = ctr + 1
      loop while ctr<num
      addBusinessDays = dt
    End Function
    %>
    Last edited by glenngv; 07-14-2004 at 05:00 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Sorry no. I'd like it so that the first date you can pick is 7 days away. For example:

    If the current date is Wed Jul 14, 2004, then the closest date you can choose is Wed Jul 21, 2004.

    Keep in mind, it needs to maintain the functionality that will only show Mon-Fri.

    Ash

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts

    Did you try my code?

    Do you mean 7 calendar days (including weekends)? That's 5 business days that you were originally mentioning. And my code does just that. You can pass the number of business days in the function parameter.

    dateDropDown "datepicker1", 30, 5

    If the current date is July 14, the first item in the dropdown list will be July 21, which is 5 business days or 7 calendar days away from the current date.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Glen,

    My apologies, your code does work. It's just that I received an error when I pasted it as is. You had:

    theday,m o,yr,dd (which threw an error - it didn't like the spaces between the m and o)

    Thank you!

    Ashley

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Glad you made it worked. The space there was produced by this forum. This forum doesn't like continuous text without space.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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