Hello. Is it possible that if i have one date in a database, say for example 1st Jan 2019, that when that is the real date, the box where people drop there files, will close, and a text box saying “the time is out, you can’t drop your files any more” or something like that? What code to i have to use to make that work?
Ok, lets start by getting todays date:
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0! var yyyy = today.getFullYear();
if(dd<10) {
dd = '0'+dd
}
if(mm<10) {
mm = '0'+mm
}
today = mm + '/' + dd + '/' + yyyy;
In today you will get todays date in a formatted way.
Then you get a date from your data collection in the results, maybe like results.items[0].expirationDate.
Then you do the same with that date first using the same code as above but on the first line you change today to expirationDate = new date(results.items[0].expirationDate) and so on.
Then you will get two variables with same formatting inside.
Then in your page.
if (today === expirationDate) {
$w("#box").show();
}
And in that box do whatever you want to Wix stunning elements.
You could build a function to use it like:
function convertDate(dateValue){
var theDate = new Date();
var dd = theDate.getDate();
var mm = theDate.getMonth()+1; //January is 0!
var yyyy = theDate.getFullYear();
if(dd<10) {
dd = '0'+dd
}
if(mm<10) {
mm = '0'+mm
}
theDate = mm + '/' + dd + '/' + yyyy;
return theDate;
}
And then use that
let today = new Date();
today = convertDate(today);
let expirationDate = results.items[0].expirationDate;
expirationDate = convertDate(expirationDate);
if (today === expirationDate) {
// It is the same date
}
Hope I helped you
Thank you for answering. I am pretty new to wix code, so i understood some of this, but where do i put in my database name so that it can compare current date to what is in the database?