...

View Full Version : date picker - making the first date five days away



AshleyQuick
07-13-2004, 06:40 PM
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


<!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>

angst
07-13-2004, 06:54 PM
you will need to use the datediff and AddDate Functions,,
try a google search.

AshleyQuick
07-13-2004, 07:31 PM
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

glenngv
07-14-2004, 03:57 AM
Do you mean you want the next 5 business days of the current date to be the first item in the dropdown list?


<%

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
%>

AshleyQuick
07-14-2004, 05:41 AM
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

glenngv
07-14-2004, 09:35 AM
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.

AshleyQuick
07-14-2004, 02:57 PM
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

glenngv
07-15-2004, 03:27 AM
Glad you made it worked. The space there was produced by this forum. This forum doesn't like continuous text without space.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum