Skip to main content
Participating Frequently
July 22, 2013
Answered

AS2 Need help in displaying a movie depending on date

  • July 22, 2013
  • 1 reply
  • 1908 views

Hi all,

I really hope someone can help me with the below. I've spent all day trying to fix it, but with no luck. I have an ad which needs to trace "Pre Release" on and before 27/08/2013. I then need to display "Out Friday" on dates 28/08/2013 - 29/08/2013. The last one I have is the tricky one. On and after 30/08/2013 I need it to display "Out Now", but with the code below I can't get this to work. After 30/08/2013 it's displaying "Pre Release" instead of "Out Now".

Sorry in advance if this isn't very clear, but any help would be greatly appreciated.

var_PreRelease = new Date(2013,8,27);

var_OutFri = new Date(2013,8,29);

var_OutNow = new Date(2013,8,30);

var_OutNow = new Date(2013,9,1);

// set up a variable for todays date

var_Today = new Date();

if(var_Today.getDate() <= var_PreRelease.getDate() )

{

trace("Pre release");

}

if(var_Today.getDate() == var_OutFri.getDate() )

{

trace("Out Friday");

}

if(var_Today.getDate() == var_OutFri1.getDate() )

{

trace("Out Friday");

}

if(var_Today.getDate() == var_OutNow.getDate() || var_Today.getDate() > var_OutNow.getDate())

{

trace("Out Now");

}

This topic has been closed for replies.
Correct answer Ned Murphy

Hi Ned,

I changed the 8 to 7 etc, but it was still displaying "Pre Release" after August 30th 2013. I have been setting the Today value to go by the users computer clock. The ad is only going to be displayed in the UK, so I have been using dd/mm/yyyy to test the values. When I change my clock, everything works as it should apart from the "Out Now" after August 30th 2013. Is it possible to have 3 else ifs? The one that works great is this one:

var PreRelease = new Date(2013, 8, 27);

var OutNow = new Date(2013, 8, 30);

// set up a variable for todays date

var Today = new Date();

if (Today.getDate() <= PreRelease.getDate()){

          trace("Pre release");

} else if (Today.getDate() < OutNow.getDate()) {

          trace("Out Friday");

} else {

          trace("Out Now");

}


Here is the code that should work....

var PreRelease = new Date(2013, 7, 27);

var OutNow = new Date(2013, 7, 30);

// set up a variable for todays date

var Today = new Date();

if (Today <= PreRelease){

          trace("Pre release");

} else if (Today < OutNow) {

          trace("Out Friday");

} else {

          trace("Out Now");

}

Here is where your code was wrong (as well as anything that's been offered to you - we're all guilty of missing seeing things with this one)...

While the 8 versus 7 remains true ( August is 7, not 8 ), your conditionals have been testing the day of the month, not the date.... the getDate() method returns the day number of the month ( 1 thru 31 ).  (Sept) 1 will test < (August) 31 when you are only testing the day numbers against each other.

You should learn to use the trace() method as a troubleshooting tool.  If you were to test the values of your conditionals you would have seen where the getDate() values were not what you wanted to be testing.

1 reply

Participating Frequently
July 22, 2013

you should use - else if

var_PreRelease = new Date(2013, 8, 27);

var_OutFri = new Date(2013, 8, 29);

var_OutNow = new Date(2013, 8, 30);

var_OutNow = new Date(2013, 9, 1);

// set up a variable for todays date

var_Today = new Date();

if (var_Today.getDate() <= var_PreRelease.getDate())

{

          trace("Pre release");

}

else if (var_Today.getDate() == var_OutFri.getDate())

{

          trace("Out Friday");

}

else if (var_Today.getDate() == var_OutFri1.getDate())

{

          trace("Out Friday");

}

else if (var_Today.getDate() == var_OutNow.getDate() || var_Today.getDate() > var_OutNow.getDate())

{

          trace("Out Now");

}

Participating Frequently
July 22, 2013

Thanks a lot for your reply! I've tried to use the code with else if, but when I view it on the 01/09/2013 it still displays "Pre Release" instead of "Out Now". It's very tricky because on the one hand I need it to display "Pre Release" before 27/08/2013, but then display "Out Now" after 30/08/2013.

Participating Frequently
July 22, 2013

What you are trying to achieve is certainly possible.  Explain how you are setting things up and show the current code you use.


Hi Ned,

thanks again. It'll be a huge help if I can get this working as I'm getting cold sweats! Below is one example of what I have. The most recent one which you helped me with was working except from the problem with the dates. Ok, so apologies if this looks like a load of mumbo jumbo.

1. I have a banner ad which needs to show "Pre Release" on and before 27th August 2013.

2. On 28th August 2013 - 29th August 2013 it needs to show "Out Friday".

3. On and after 30th August 2013 it needs to show "Out Now".

The problem I'm having is that because I already have a variable preRelease which I then say if the date is before 27th August, show this, then when it gets to the 1st of September, it's going back to that code.

var PreRelease = new Date(2013,8,28);

var OutFri = new Date(2013,8,29);

var OutNow = new Date(2013,8,31);

// set up a variable for todays date

var Today = new Date();

if(Today.getDate() <= PreRelease.getDate() || Today.getDate() > OutFri.getDate() )

{

trace("Pre release");

}

if(Today.getDate() == OutFri.getDate() || Today.getDate() < OutNow.getDate() )

{

trace("Out Friday");

}

if(Today.getDate() == OutNow.getDate() || Today.getDate() <= OutNow.getDate() )

{

trace("Out Now");

}