Click here to Skip to main content
15,896,478 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Am working on a reservation room ticket booking website.i got a error,the error was i have a from date and to date when i select from date and to date and submit the reservation details into the data base..
the value will saved into this type..

From date : 25/08/2014
To date : 29/08/2014

Problem: when i book another reservation details i dont want the date between 25/08/2014 to 29/08/2014. the between dates are not saved in database.only the from date and to date are saving into the database.how to block between date using sql...
Posted
Comments
george4986 23-Aug-14 6:37am    
post ur code here

1 solution

1)First you can find all the dates between from and to dates in SQL Server like
Create PROCEDURE getAllDaysBetweenTwoDate
(
@FromDate DATETIME,    
@ToDate DATETIME
)
AS
BEGIN
    
    DECLARE @TOTALCount INT
    SET @FromDate = DATEADD(DAY,-1,@FromDate)
    Select  @TOTALCount= DATEDIFF(DD,@FromDate,@ToDate);

    WITH d AS 
            (
              SELECT top (@TOTALCount) AllDays = DATEADD(DAY, ROW_NUMBER() 
                OVER (ORDER BY object_id), REPLACE(@FromDate,'-',''))
              FROM sys.all_objects
            )
        SELECT AllDays From d
        
    RETURN 
END
GO


then compare selected date with the result set.

2)At Code Behind:
Get the all dates between from and to dates through loop then compare with selected date.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900