[SOLVED ]Javascript | Allow Date Function Date Element | minDate and maxDate + SOLUTION

marcq

Member
Hi,

I would like to set a minDate and a maxDate to one of my date element.

minDate should be 2017-05-03 (all dates before this date are disabled)
maxDate should be 2017-10-09 (all dates after this date are disabled)

I guess it should be something like this, but couldn't solve it :

JavaScript:
var minDate = new Date('2017-05-03');
var result = minDate < 0 ?true : false;

I have already the following code into the Allow date function of my date element field :

JavaScript:
var diff = new Date().compare(new Date(date));
var result = diff < 0 ?true : false;

var testYear = new Date(date).format('%Y').toInt();
var thisYear = new Date().format('%Y').toInt();
var result  = testYear !== thisYear;

Would appreciate your expertise.

Thanks, marc
 
Hi,

Would appreciate some help here, I tried this but of course doesn't work.

Basically I would need to display a date range from 2017-05-04 to 2017-10-09 and in this date range only allow future dates.

Thanks, marc
 
Last edited:
ok I solved it with a database query.

I have created a table call fab_seasondates containing all dates that should not be available because out of the date range | off-season :

I have changed the "PHP Allow date function" of my date element in particular my query by adding the following union statement :

Code:
UNION SELECT DATE(fab_seasondates.book_bookingdate) FROM fab_seasondates LEFT JOIN fab_booking_taken as t3 ON DATE(fab_seasondates.book_bookingdate) = DATE(t3.book_date)

Code:
$myDb = JFactory::getDbo();

$myQuery = $myDb->getQuery(true);
$myQuery = "SELECT DATE(fab_booking.book_bookingdate) FROM fab_booking LEFT JOIN fab_booking_taken as t1 ON DATE(fab_booking.book_bookingdate) = DATE(t1.book_date) UNION SELECT DATE(fab_blockeddates.book_bookingdate) FROM fab_blockeddates LEFT JOIN fab_booking_taken as t2 ON DATE(fab_blockeddates.book_bookingdate) = DATE(t2.book_date) UNION SELECT DATE(fab_seasondates.book_bookingdate) FROM fab_seasondates LEFT JOIN fab_booking_taken as t3 ON DATE(fab_seasondates.book_bookingdate) = DATE(t3.book_date)";
$myDb->setQuery($myQuery);
$bookedDates = $myDb->loadColumn();

$begin = new DateTime();
$end = new DateTime('2026-12-31');

$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($begin, $interval, $end);

$myAllowedDates = array();

foreach( $period as $dt ) {
    $thisDate = $dt->format("Y-m-d");
    if (!in_array($thisDate, $bookedDates)) {
    $myAllowedDates[] = $thisDate;
    }
}
return $myAllowedDates;

Now it is working and the dates contain in the f
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top