Date problem

Results 1 to 2 of 2

Thread: Date problem

  1. #1
    Join Date
    Dec 1969

    Default Date problem

    Hi all,<BR>I am making an online hotel reservation program using ASP.<BR>I want to check if there is any data already present for a <BR>particular date range as given by the user <BR>for hotel enqury.I am using SQL server DB.<BR><BR>Suppose I have data as below:<BR><BR>1 first program1 01/01/2002 01/14/2002<BR>2 second program2 01/22/2002 02/31/2002<BR><BR>I guess there will be 3 probale cases we will encounter <BR>i.e <BR>(a) the from date and to date entered by user fall within <BR>the From & To dates stored in DB.<BR><BR>(b) the from date and to date entered by user is not <BR>within the dates stored.<BR><BR>(c) the from date and to date entered by user falling <BR>partially within the dates range stored.<BR><BR>Also I don&#039;t know in which format the DB stores the <BR>dates...<BR><BR>So what will be the query I should use to get the result??<BR>Hope i have explained the problem clearly. Still any doubt <BR>please inform me. I need it urgently.<BR><BR>Tahnks in advance...<BR>-Santosh <BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Date problem

    &#062; I don&#039;t know in which format the DB stores the <BR>dates...<BR><BR>It uses an internal format that is very strange. YOU DO NOT CARE what this format is! It is *NOT* important! SQL Server will quite happily translate strings to dates and dates to strings for you. And VBScript will quite happily do the same thing. So don&#039;t worry about it.<BR><BR>******************<BR><BR>Now, a question: Do you *care* whether the range of dates given by the user fall entirely within a range in the DB (as opposed to only partially)? Or do you just care if there is *any* overlap?<BR><BR>To test for *any* overlap:<BR><BR>SELECT * FROM table <BR>WHERE startDate &#060;= &#039;...user end date...&#039;<BR>AND endDate &#062;= &#039;...user start date...&#039;<BR><BR>From VBScript code:<BR><BR>&#060;%<BR>SQL = "SELECT * FROM table " _<BR>&nbsp; &nbsp; & " WHERE startDate &#060;= &#039;" & userEndDate & "&#039; " _<BR>&nbsp; &nbsp; & " AND endDate &#062;= &#039;" & userStarDate & "&#039; "<BR>%&#062;<BR><BR>That will find all overlaps, full or partial, if I&#039;ve done the logic right.<BR><BR>See if you can follow the logic of it.<BR>

Posting Permissions

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