Display Alert at the Specified Date and Time in jQuery

Last Updated on April 1, 2024 by Roshan Parihar

If you want to display an alert at the specified date and time, you have to use the Date() and getTime() It also requires using of the setTimeout() function and passing the specified date and time as its argument.

How to Display Alert at the Specified Date and Time

First, create a form with the input as date and time to be specified by the users. You can use the <input type="datetime-local"> type of the form element to get the user’s datetime input. See the date and time input in the added form.

Now, to display the alert at the specified date and time, you have to use the jQuery script as given below. Add the jQuery library with the library URL. After that, get the input date and time value of the form on the button click.

The below script matches the specified date and the current date. The specified date should be greater than the current date to display the alert.

You have to find the difference between the current date and the specified date. It should only display the alert when the difference between the specified and current dates is greater than zero. See the example given below to learn the method.

Test it Live

You can check the live example with the ‘Test it Live’ button given above. In the test live example, select the date and time when you want to display the alert. After that, click the submit button and wait until you reach your date-time. You will get an alert at your specified date and time.

So, this a simple example but useful when you want to display alerts to your audience.

You May Also Like to Read

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.