Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to see if day is Saturday or Sunday, 0 or 6 using getDay()==1 and getday()==0, if it is dont add the date and time to my select option.

JavaScript
    var from = new Date(firstNewDt);
    var to = new Date(start);
    var day = from.getDate();

    if (from.getHours() <= 16 && from.getMinutes() <= 30 && from.getHours() >= 8 && from.getDay()==0||from.getDay()==1) {



            if (day <= 9) {
                day = "0" + day;
            }
            var month = from.getMonth() + 1;
            if (month <= 9) {

                month = "0" + month;
            }
            var year = from.getFullYear();
            var hours = from.getHours();
            if (hours < 10) {
                hours = "0" + hours;
            }

            var minutes = from.getMinutes();
            if (minutes < 30) {
                minutes = "0" + minutes;
            }


            var dayto = to.getDate();
            if (dayto <= 9) {
                dayto = "0" + dayto;
            }
            var monthto = to.getMonth() + 1;
            if (monthto <= 9) {
                monthto = "0" + monthto;
            }
            var yearto = to.getFullYear();
            var hoursto = to.getHours();
            if (hoursto < 10) {
                hoursto = "0" + hoursto;
            }
            var minutesto = to.getMinutes();
            if (minutesto < 30) {
                minutesto = "0" + minutesto;
            }



            bookedFreeTimes.push(year + "-" + month + "-" + day + " " + hours + ":" + minutes + " , " + yearto + "-" + monthto + "-" + dayto + " " + hoursto + ":" + minutesto);


        }

}


Here is my code i add my values to an array and then display them.

Right now if i add the value 2014-12-10 12:00 to 2014-12-10 12:30

i then add days -5 from StartDate, and +5 days from Endate,

So i am quering from 2014-12-05 12:00 to 2014-12-15 12:30
so its should not display 6,7 dec, and 13,14 dec so right now it it dony display 6 dec and and 13 dec so its not displaying saturdays but sundays its displaying why?

UPDATE
=================
Should i have like this?
JavaScript
if (from.getHours() <= 16 && from.getMinutes() <= 30 && from.getHours() >= 8 && (from.getDay() == 0||  from.getDay() == 1))


Because like this it still displays 7, and 14 december
Posted
Updated 8-Dec-14 20:03pm
v2

&& has precedence over || so if you do not use parentheses as you mean you get the wrong condition check!!!
In your case you wrote
JavaScript
if(a && b && c && d || e)

which is equal to
JavaScript
if((a && b && c && d) || e)

but probably you meant
JavaScript
if(a && b && c && (d || e))
 
Share this answer
 
Comments
Kurac1 9-Dec-14 2:02am    
I have updated, do u mean like that?
Kornfeld Eliyahu Peter 9-Dec-14 2:25am    
Yes - it seem to me good now...
Quote:
i want to see if day is Saturday or Sunday, 0 or 6 using getDay()==1 and getday()==0, if it is dont add the date and time to my select option.

then your conditions would be
JavaScript
if (from.getHours() <= 16 && from.getMinutes() <= 30 && from.getHours() >= 8 && !(from.getDay() ==0 || from.getDay()==6)) {


note that you have to use brackets and change the from.getDay()==1 to from.getDay()==6
 
Share this answer
 
v4
Comments
Kurac1 9-Dec-14 2:07am    
I doesnt work like that it displaying from 6dec to 14 dec
Kurac1 9-Dec-14 2:09am    
So it have removed 5 dec friday and 15 dec Monday
Kurac1 9-Dec-14 2:11am    
it dont display from 8-12 dec now :S
DamithSL 9-Dec-14 2:21am    
Ok then you have to use ! before the ()
Kurac1 9-Dec-14 2:21am    
It works nows

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900