Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Date comparison for validation.

Explorer ,
Jul 07, 2023 Jul 07, 2023

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");

}

TOPICS
ActionScript , Code , How to
582
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 07, 2023 Jul 07, 2023

use the getTime() method of the date object

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 09, 2023 Jul 09, 2023

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");                    
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 10, 2023 Jul 10, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 10, 2023 Jul 10, 2023

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 10, 2023 Jul 10, 2023

yes, you should retrieve it from your server or a public source.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 10, 2023 Jul 10, 2023

Would it be a website that is online, or something?

Exemple: https://www.horariodebrasilia.org

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 10, 2023 Jul 10, 2023

you would use your web host or a public site that supplies the timedate.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 10, 2023 Jul 10, 2023

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2023 Jul 11, 2023

what kind of app are you building with animate?  (eg, canvas, mobile app, something else?)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 12, 2023 Jul 12, 2023

I'm structuring a desktop application, @kglad 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2023 Jul 12, 2023
LATEST
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines