Copy link to clipboard
Copied
Hi people, good afternoon!
I would like to know how I can be creating a code that expires within a time, using getDate and time.
For example, having an input field, where I check if a token exists, and compare the dates to check if it is active within the period.
(example):
new InitialDate: DD/MM/YY
new EndDate: DD/MM/YY
function ... {
if(code.text = "itsCode")
{
if(InitialDate > EndDate)
{
gotoAndStop(2);
}
else
{
trace("error, expired");
}
Copy link to clipboard
Copied
use the getTime() method of the date object
Copy link to clipboard
Copied
Hi Kosglad, can't find a way to get getData to add to the variable.
I put together this code and I'm still wondering how I can add, in date_now, the current date of the user.
Can you help me?
var date_start:Date = new Date(2023, 6, 10);
var date_now:Date = new Date(); // HERE!
var differenceInMilliseconds:Number = date_end.time - date_start.time;
const MILLISECOND_PER_SECOND:int = 1000;
const SECOND_PER_MINUTES:int = 60;
const MINUTES_PER_HOUR:int = 60;
const HOURS_PER_DAY:int = 24;
var differenceInSeconds:Number = differenceInMilliseconds / MILLISECOND_PER_SECOND;
var differenceInMinutes:Number = differenceInSeconds / SECOND_PER_MINUTES;
var differenceInHouse:Number = differenceInMinutes / MINUTES_PER_HOUR;
var differenceInDays:Number = differenceInHouse / HOURS_PER_DAY;
if (date_now > date_end)
{
trace("expired");
}
else
{
trace("approved");
}
Copy link to clipboard
Copied
don't you see an error?
the third line of your code contains date_end which is undefined.
p.s. there's no need to convert from ms to anything else when doing date comparisons unless you want to check for a certain number of seconds, or minutes, or hours etc.
Copy link to clipboard
Copied
I understood!
I managed to make the code work with your help, however, I checked a possible loophole to fix.
If the user adjusts the configuration for a date earlier than the defined one, the code will indicate that it is approved.
In the Date 'now' variable, is there any way I can get this information online, without the need to be from the user's device?
Copy link to clipboard
Copied
yes, you should retrieve it from your server or a public source.
Copy link to clipboard
Copied
Would it be a website that is online, or something?
Exemple: https://www.horariodebrasilia.org
Copy link to clipboard
Copied
you would use your web host or a public site that supplies the timedate.
Copy link to clipboard
Copied
No reference articles, I couldn't identify a function that I can add a parameter like site, or similar for verification.
Would you help me?
Copy link to clipboard
Copied
what kind of app are you building with animate? (eg, canvas, mobile app, something else?)
Copy link to clipboard
Copied
I'm structuring a desktop application, @kglad
Copy link to clipboard
Copied
then get the data from a public source, https://sproutsocial.com/insights/dates-times-application-development/