screen_rotation
Copied to Clipboard
<html> <head> <meta charset="UTF-8"> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <div id="app"> <h3>Vue Js Compare two dates</h3> <input type="date" v-model="date1"> <input type="date" v-model="date2"> <button @click="compareDates" :disabled="!date1 || !date2">Compare Dates</button> <p v-if="result">{{ result }}</p> <p v-if="!result && submitted">Please enter valid dates.</p> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { date1: '', date2: '', result: '' } }, methods: { compareDates() { const date1 = new Date(this.date1); const date2 = new Date(this.date2); if (date1.getTime() === date2.getTime()) { this.result = 'The dates are equal'; } else if (date1.getTime() > date2.getTime()) { this.result = 'Date 1 is later than date 2'; } else { this.result = 'Date 2 is later than date 1'; } } } }); </script> <style scoped> #app { display: flex; flex-direction: column; align-items: center; margin: 50px auto; width: 80%; max-width: 600px; } h3 { font-size: 24px; margin-bottom: 20px; } input[type="date"] { padding: 8px 10px; border: 1px solid #ccc; border-radius: 5px; margin-bottom: 20px; } button { padding: 10px 20px; background-color: #4CAF50; color: #fff; border: none; border-radius: 5px; cursor: pointer; margin-bottom: 20px; } button:disabled { background-color: #ccc; cursor: not-allowed; } p { margin-bottom: 20px; font-size: 18px; } </style> </body> </html>