p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: reservation system based on date and time


Message #1 by dont worry <aspmailbox@y...> on Mon, 18 Mar 2002 06:41:47 -0800 (PST)
Ken,
I've taken your idea a step further.  Below is WORKING
code.  Just copy and paste into a asp file.  Please
CHECK it as I have added another if statement that I
think covers all possiblities.  I will add the TIME
later (guessing it should still work), this is yours
to do as you wish, and thanks a million!

*************begin code
<%

'*******************
'CODE PROVIDED BY DONTWORRY AVA. AT
ASPMAILBOX@Y...
'PLEASE NO KUDOS JUST PASS IT FORWARD
'THANKS TO KEN SCHAEFER FOR THE WISDOM
'******************


response.write "Overlapping date function<BR>"

dim EstDate, EedDate
dim PstDate, PedDate
dim same_page
EstDate = date()
EedDate = date() +9



same_page  = Request.ServerVariables("SCRIPT_NAME")
PstDate = request.form("proposedSTDate")
PedDate = request.form("proposedEDDate")

response.write "Existing Dates "& EstDate &" to "
&EedDate &"<BR>"
response.write "Proposed Dates " &PstDate &" to " &
PedDate &"<BR>"


if request.form("token") ="" then
	call build_form
else
	call process_dates
end if



sub build_form
%>
<form action="<%=same_page%>" method="POST">
Proposed StartDate<input type="text"
name="proposedSTDate" value="<%=PstDate%>"><BR>
Proposed EndDate<input type="text"
name="proposedEDDate" value="<%=PedDate%>"><BR>

<input type="submit" value="submit"
<input type="hidden" name="token" value="1">
</form>
<%end sub%>



<%sub process_dates

if FORMATDATETIME(EstDate) < FORMATDATETIME(PstDate)
AND FORMATDATETIME(EedDate) > FORMATDATETIME(PedDate)
Then
	response.write "Yes Overlapping 1"

elseif FORMATDATETIME(EstDate) >
FORMATDATETIME(PstDate) AND FORMATDATETIME(EedDate) <
FORMATDATETIME(PedDate) Then
	response.write "Yes Overlapping 2"

elseif FORMATDATETIME(EstDate) <
FORMATDATETIME(PedDate) AND FORMATDATETIME(EedDate) >
FORMATDATETIME(PedDate) Then
	response.write "Yes Overlapping 3"

elseif FORMATDATETIME(EstDate) <
FORMATDATETIME(PstDate) AND FORMATDATETIME(EedDate) >
FORMATDATETIME(PstDate) Then
	response.write "Yes Overlapping 4"


else
	response.write "No Overlapping"
end if

call build_form
end sub
%>

****************end code




--- Ken Schaefer <ken@a...> wrote:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> From: "dont worry" <aspmailbox@y...>
> Subject: [proasp_codeclinic] Re: reservation system
> based on date and time
> 
> 
> : <question_by_example>
> : How should I set this up and how will it work.
> : User (A) enters a class date of 
> : <startdatetime>3/4/2002 9:00am</startdatetime>
> : <enddatetime>3/4/2002 9:45am</enddatetime>
> : 
> : Should i insert this in to 2 diff. columns
> : (startdatetime) & (enddatetime) or 4 diff. columns
> : (startdate)&(starttime) & (enddate)& (endtime)?
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Just two. Your attribute is a starting date/time,
> and an ending date/time - why do you need extra
> columns?
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> : User (B) enters a class date of 
> : <startdatetime>3/4/2002 8:00am</startdatetime>
> : <enddatetime>3/4/2002 9:30am</enddatetime>
> : 
> : In the above example the User (B)'s TIME overlap
> on
> : User (A) time so I should give an error.
> : What will the query look like to ensure that time
> do
> : not overlap like this? Will it be between
> : startdatetime & enddattime or some kind of date
> : difference?
> : </question_by_example>
> : Is there any online reference or examples I could
> use?
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Draw a line that indicates the length of time of a
> proposed booking. Now draw more lines to indicate
> possible overlaps (eg see rudimentary diagram
> below). Red is the proposed booking. Blue are the
> overlapping bookings.
> 
> |----------|
> |-----------------------|
>         |----------|
>           |-------|
>                        |--------------|
> 
> The above are all the possible ways a proposed
> booking can overlap with an existing booking. If
> none of the conditions exist, you enter the proposed
> booking in the database.
> 
> Thus if (ST=StartTime, ET=EndTime)
> (
>     ExistingST < ProposedST AND ExistingET >
> ProposedET -- covers first two possibilities
> OR
>     ExistingST > ProposedST AND ExistingET <
> ProposedET -- covers 3rd possiblity
> OR
>     ExistingST < ProposedET AND ExistingET >
> ProposedET -- covers 4th possiblity
> )
> then you have an overlapping condition. If the
> Recordset is EOF then there is no overlap, and you
> can insert the new booking.
> 
> Cheers
> Ken
> 
> 
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage
http://sports.yahoo.com/

  Return to Index