Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mawunyo's avatar

Vujes form check if selected date is greater than tomorrow

His I want to check if the datetime select by user is greater than tomorrow and return to him an error.

This is my script. Please help me .

callFunction: function () {

      var tomorrow = new Date();
      var date = tomorrow.getFullYear()+'-'+(tomorrow.getMonth()+1)+'-'+(tomorrow.getDate() + 1);
      var time = tomorrow.getHours() + ":" + tomorrow.getMinutes() + ":" + tomorrow.getSeconds();
      var dateTime = date+' '+time;

      if(this.form.start >= dateTime){
        swal.fire(
            'Oops !',
            'The date you have chosen must be more than 24 hours.',
            'warning'
          )
      }
      console.log(dateTime);
    }
0 likes
1 reply
khalilm's avatar

Due to timezone, different days in months, leap years, it is sometime easier to use a package that will handle all the complexity of time calculations for you.

In my case since I have a lot of these types of calculations I use a package called moment.js (https://momentjs.com/) which you can add easily to your vuejs app.

Please or to participate in this conversation.