Copy link to clipboard
Copied
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");
}
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 ( A
...Copy link to clipboard
Copied
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");
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You cannot define two values for the same variable and expect the code to be able to differentiate between them... it will equal the last value you assigned.
If the Out Now is supposed to start on the 30th, then make the value the 30th
var_PreRelease = new Date(2013, 8, 27);
var_OutFri = new Date(2013, 8, 29); // not needed
var_OutNow = new Date(2013, 8, 30);
var_OutNow = new Date(2013, 9, 1); // not needed
// 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_OutNow.getDate()) {
trace("Out Friday");
} else {
trace("Out Now");
}
Copy link to clipboard
Copied
Thank you very much Ned! This is exactly what I needed. Everything is working perfectly apart from one thing. When I test it by changing my clock to 01/09/2013, it still displays "Pre Release" rather then "Out Now". It's really a tough one for me because even though I need it to display "Pre Release" before the 27th August 2013, I also need it to display "Out Now" after the 30th August. For some reason it displays "Pre Release" after the 30th, and I need it to display "Out Now".
On your advice I've changed it to this:
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 (var_Today.getDate() <= var_PreRelease.getDate()){
trace("Pre release");
} else if (var_Today.getDate() < var_OutNow.getDate()) {
trace("Out Friday");
} else {
trace("Out Now");
}
I just don't know how to make it so that it will display "Out Now" on the 30th and after. When it hits September 1st 2013, it goes back to saying "Pre Release".
Thanks very much for your help on this!
Copy link to clipboard
Copied
I missed this earlier probably for the same reason as anyone - different date formats being used in the discussion... I paid less attention to it because I'm in the US and we read dates as mm/dd/yyyy, not dd/mm/yyyy.
If you are setting a date based on August being the 8th month of the year, August is not month 8 in most coding languages, it is month 7 because months start at 0.
Use:
var_PreRelease = new Date(2013, 7, 27);
var_OutNow = new Date(2013, 7, 30);
Copy link to clipboard
Copied
Thanks Ned! Yeh I can understand the confusion with the dates! I've tried what you suggested, but unfortunately it still shows "pre release" after 30th August 2013. I've been struggling with this all day, and I'm not even sure if what I need to achieve is possible!
Copy link to clipboard
Copied
What you are trying to achieve is certainly possible. Explain how you are setting things up and show the current code you use.
Copy link to clipboard
Copied
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");
}
Copy link to clipboard
Copied
It looks like you did not follow my earlier posting... change the months to one less than they are... 8 becomes 7, 9 becomes 8
Then explain how you are setting the Today value to be the dates you test.
Copy link to clipboard
Copied
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");
}
Copy link to clipboard
Copied
If this helps, I had this to work with, but I needed to add 3 variables instead of just one:
stop();
// EDIT THE FOLLOWING RELEASE INFO:
var releaseYear = 2013;
var releaseMonth = 8;
var releaseDay = 30;
// **DO NOT EDIT THE FOLLOWING CODE**
// ------------------------------------------------------------------
eventDate = new Date(releaseYear, (releaseMonth-1), releaseDay);
eventMillisecs = eventDate.getTime();
currentDate = new Date();
currentMillisecs = currentDate.getTime();
this.msecs = eventMillisecs-currentMillisecs;
if (this.msecs<=0) {
gotoAndStop(2);
}
// ------------------------------------------------------------------
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Ned, thank you so much for all your help on this! The last one you sent works perfectly! Thank you very much, and the good thing is you've taught me about the getDate method, when to use it and when not to use it. I can't thank you enough. To finally see the code working was a great feeling as I was working on it all day yesterday. You've been a great help and I hope one day I will be able to offer the same help to somebody. Have a great Tuesday!
Copy link to clipboard
Copied
You're welcome
Copy link to clipboard
Copied
... and use the code I provided earlier for the conditional as well. What you had to start with is wrong, and what you just sjowed is different and wrong, so no use going there
Find more inspiration, events, and resources on the new Adobe Community
Explore Now