Answered
HOW TO SET A JAVA FILE EXPIRY DATE ?
I
I already have a java script, I want to add expiry date in it, how to do it. Please give me the code. and how to do it
I
I already have a java script, I want to add expiry date in it, how to do it. Please give me the code. and how to do it
var today = new Date(); alert(today);
How to add this code??
var today = new Date(); alert(today);How to add this code??
By @MJ ST
You would research how to work with dates with JavaScript, among a few other things.
Here is a working demo for you. It is not guaranteed to be fit for purpose or covered by warranty. Use at your own risk!
/*
Today's date: 2024-10-18
Expires tomorrow: 2024-10-19
*/
// Get today's date
var today = new Date();
var year = today.getFullYear().toString();
// Extract the month... Months are zero indexed, so add one!
var month = ("0" + (today.getMonth() + 1)).slice(-2);
var date = ("0" + today.getDate()).slice(-2);
var yyyymmdd = year.toString() + month.toString() + date.toString();
// Convert the string back to a number
yyyymmdd = parseInt(yyyymmdd);
// Conditional
if (yyyymmdd < 20241019) {
// Add your code below. Remove the following alert...
alert("Pass");
} else {
// Do nothing on fail. Remove the following alert...
alert("Fail");
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.