I am working on a project which need to be converted into asp.net application using webform $ c#.
Below is a working script in jQuery that generate the date of next 90 days from current date based on the calendar.
This is a simple script it doesn't look for blocked dates etc..
It also show only dates of weekdays ie from Mon - Friday.
$(function(){
function pad(n){return n<10 ? '0'+n : n}
var date = new Date();
var selectElement = $('<select name="dddDate" class="ddDate" >'), optionElement;
for (var count =0; count < 91; count++){
var day = date.getUTCDay();
if (day == 0 || day == 1 || day == 2 || day == 3 || day == 4 || day == 5) {
formattedDate = pad(date.getUTCDate()) + '-' + pad(date.getUTCMonth()+1) + '-' + date.getUTCFullYear();
optionElement = $('<option>')
optionElement.attr('value',formattedDate);
optionElement.text(formattedDate);
selectElement.append(optionElement);
}
date.setDate(date.getDate() +1);
}
$('#ddDate').append(selectElement);
});
This was easy. Now i have to generate these dates from two different table EventCalender
& Booking
Table I have to see which dates are blocked or booked and accordingly show only those dates which are available for next 90 days.
Let us assume EventCalender
has BlockDate
Column & Booking
Table also has BlockDate
column.
I would appreciate if some can help to generate a sql query which will generate available dates based on blocked dates in two tables and fill the drop down. Any idea or a pointer would be great ....
I looked for such example but could not find much help ..
Since you aren't using SQL to generate the available dates, then why use it to prune this list?
Just load in the blocked and event dates, and just remove these dates from the list.
In order to do what you want, using SQL, I expect you would need to populate a table with the available dates, then do an outer join on these other two tables and only select the rows where the blocked and event tables are null.
Here is one way to generate the dates in SQL.
I am assuming you are using the date
data type in your blockeddate columns.
declare @date date = getdate()
;with dates(d)
as
(
select @date
union all
select DATEADD(day, 1, d)
from dates
where d < DATEADD(day, 89, @date)
)
select *
from dates
except
(
select blockedDate
from table1
union all
select blockedDate
from table2
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.