Hello everyone,
Question:
Verifiy if pitches of the camping are available
**Product:**Wix EDITOR
On my campsite website, I have a collection called ‘RESERVATIONS’.
In this collection, I have fields such as:
-Arrival Date
-Departure date
-Location number.
etc…
When requesting a customer reservation (by telephone for example), I would like to check that the location I am offering the customer is available and is not reserved in the coming days. To do this, I run a query which checks the pitch number and the dates.
I Iwant to chek ,if between the arrival and the departure of the new reservation i a m registering, the location is available or not in the entered period.
So in my opinion, the pitch is availabalble if:
-
First condition : BOTH arrival date AND departure date of the new reservation are anterior of the Arrival AND departure dates in the collection "RESERVATIONS?
-
Second condition : BOTH arrival date AND departure date of the new reservation are posterior of the departure AND anterior of departure dates in the collection "RESERVATIONS? I am a little bit lost … 
What do you think of this?
Thank for your help.
Here my code below:
$w(‘#VerifierDispos’).onClick((event) => {
const arriveeDate = new Date($w(‘#Arrivee’).value);
const departDate = new Date($w(‘#Depart’).value);
wixData.query(‘Reservations’)
.eq(“saison”, “2025”)
.eq(“emplacement”,$w(‘#NumEMP’).value)
.eq(arriveeDate < ‘Arrivee’ && departDate <= ‘Depart’)
.eq(arriveeDate >= ‘Depart’ && departDate < ‘Arrivee’)
.find()
.then(async (results) => {
console.log(results.items[0]);
if (results.length > 0) {
console.log("L'emplacement est INDISPONIBLE pour cette période : impossible de le louer.")
} else {
console.log("L'emplacement est DISPONIBLE pour cette période.")
}
})
});
Hi, @Mairie_MAILLY_LE_CHA !!
Why not try using .lt()
, .le()
, .gt()
, or .ge()
when comparing dates? 
1 Like
Thank You @Onemoretime. I’ll try this and tell you.
have a nice day
1 Like
Hello
At your request I have integrated the operators.lt()
, .le()
, .gt()
, or .ge()
[/quote]
I have also inserted 4 conditions.
The code is ok : No errors. The pb is that is doesn’t find any record, so I think that my “DATE” formats are not recognized.
I tried just with a simple condition (Not 4):
const Condition1 = wixData.filter()
.ge(‘arrivee’, ArriveePrevue)
It should display several reservations (which arrive after this date according to the condition): it does not find any.
I join you 2 screenshots:
First one : my collection RESERVATION
for the search with the fields Arrivee
and Départ
Second one : My “search bar” with 2 fields Arrivee Prévue
et Depart Prévu
.
here my new code with the new operators :
$w(‘#VerifierDispos’).onClick(async () => {
const ArriveePrevue = new Date($w('#ArriveePrevue').value);
const DepartPrevu = new Date($w('#DepartPrevu').value);
if (ArriveePrevue && DepartPrevu) {
const Condition1= wixData.filter()
.ge('arrivee', ArriveePrevue)
.lt('arrivee', DepartPrevu);
const Condition2 = wixData.filter()
.ge('depart', ArriveePrevue)
.le('depart', DepartPrevu);
const Condition3 = wixData.filter()
.lt('arrivee', DepartPrevu)
.gt('depart', ArriveePrevue);
const Condition4 = wixData.filter()
.ge('arrivee', ArriveePrevue)
.le('depart', DepartPrevu);
const ToutesConditions = Condition1.or(Condition2).or(Condition3).or(Condition4);
try {
await $w('#MesReservations').setFilter(ToutesConditions)
displayMessage9("Les filtres ont été appliqués.")
$w('#Messagetext9').expand()
} catch (error) {
displayMessage9("Erreur dans les filtres,merci de vérifier vos dates...")
$w('#Messagetext9').expand()
}
} else {
displayMessage9("Merci de bien vouloir sélectionner une DATE d'ARRIVEE et une DATE DE DEPART.")
$w('#Messagetext9').expand()
}
});
Thank for your help.
If you’re unsure where the mistake is, try loosening the conditions and simplifying the scenario as much as possible. If you can retrieve items this way, it might give you a clue. Trying to achieve a complete solution from the start often doesn’t work well. Instead, check step by step what is working and where it starts to fail. You can also use .getItems()
in the middle of the code to see if any items are being retrieved. 
That’s exactly what I did: So I tried to retrieve the data from a single condition :
const Condition1= wixData.filter()
.ge(‘arrivee’, ArriveePrevue)
From this condition, it must show me the results (because they are indeed present).
But it still doesn’t show me anything. I’m looking at the format of the dates… I’ll get back to you
THANKS
Hi, just to tell you everything is ok. My code was OK : just a pb of dates in my collection.
Thank you for your help
1 Like