Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Number of day week in javascript

Number of day week in javascript

Scheduled Pinned Locked Moved JavaScript
javascript
6 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mazdak
    wrote on last edited by
    #1

    Hello everybody, I have a Calendar in my page and I want to check if users select Saturday or Sundays, with getDay() function I can check day number, but I find out depend on operating system setting I get different number for Saturday or Sunday. So how is a proper way I can check this and be sure it is secure for every operating system settings. Regards

    Mazy
    "This chancy chancy chancy world."

    K 1 Reply Last reply
    0
    • M Mazdak

      Hello everybody, I have a Calendar in my page and I want to check if users select Saturday or Sundays, with getDay() function I can check day number, but I find out depend on operating system setting I get different number for Saturday or Sunday. So how is a proper way I can check this and be sure it is secure for every operating system settings. Regards

      Mazy
      "This chancy chancy chancy world."

      K Offline
      K Offline
      Keith Barrow
      wrote on last edited by
      #2

      That's odd behaviour - can you post the code please, including where you Parse the date out (if applicable, including date format)? In any case it probably isn't an OS thing, but a timezone/localisation problem (which happen to be different on the two OSs you are trying). In the mean time you can try getUTCDay(), but I doubt it'll fix your problem.

      KeithBarrow.net[^] - It might not be very good, but at least it is free!

      M 2 Replies Last reply
      0
      • K Keith Barrow

        That's odd behaviour - can you post the code please, including where you Parse the date out (if applicable, including date format)? In any case it probably isn't an OS thing, but a timezone/localisation problem (which happen to be different on the two OSs you are trying). In the mean time you can try getUTCDay(), but I doubt it'll fix your problem.

        KeithBarrow.net[^] - It might not be very good, but at least it is free!

        M Offline
        M Offline
        Mazdak
        wrote on last edited by
        #3

        Thanks, Yes it can be for timezone/localisation problem too. Here is my code: function ff_bfQuickMode7256046_validation(element, message) { if(element.value == '' ) return 'Please select a date for your apppointement.\n'; var myday = new Date(element.value) ; myday.setDate(myday.getDate()); var weekday = myday.getDay(); alert(weekday); if (weekday == 6 || weekday == 0 ) { if (message=='') message = element.name+" faild in my test.\n" message = 'We are close on Saturdays and Sundays.\n'; ff_validationFocus(element.name); return message; } // if return ''; } // ff_bfQuickMode7256046_validation The probelm is I get two different numbers for WEEKDAY on two different computer. So are you telling me that getDay() should return the same value globaly for all OS or setting..?

        Mazy
        "This chancy chancy chancy world."

        K 1 Reply Last reply
        0
        • M Mazdak

          Thanks, Yes it can be for timezone/localisation problem too. Here is my code: function ff_bfQuickMode7256046_validation(element, message) { if(element.value == '' ) return 'Please select a date for your apppointement.\n'; var myday = new Date(element.value) ; myday.setDate(myday.getDate()); var weekday = myday.getDay(); alert(weekday); if (weekday == 6 || weekday == 0 ) { if (message=='') message = element.name+" faild in my test.\n" message = 'We are close on Saturdays and Sundays.\n'; ff_validationFocus(element.name); return message; } // if return ''; } // ff_bfQuickMode7256046_validation The probelm is I get two different numbers for WEEKDAY on two different computer. So are you telling me that getDay() should return the same value globaly for all OS or setting..?

          Mazy
          "This chancy chancy chancy world."

          K Offline
          K Offline
          Keith Barrow
          wrote on last edited by
          #4

          AFAICT it should - people seem to have problems parsing the date in the first place. I'd put a breakpoint on/after this line:

          var myday = new Date(element.value) ;

          myday will probably be different across the OSs (and possibly browsers). You might be better off splitting element.value yourself and using the constructor function Date (_year, month, day_)

          KeithBarrow.net[^] - It might not be very good, but at least it is free!

          M 1 Reply Last reply
          0
          • K Keith Barrow

            That's odd behaviour - can you post the code please, including where you Parse the date out (if applicable, including date format)? In any case it probably isn't an OS thing, but a timezone/localisation problem (which happen to be different on the two OSs you are trying). In the mean time you can try getUTCDay(), but I doubt it'll fix your problem.

            KeithBarrow.net[^] - It might not be very good, but at least it is free!

            M Offline
            M Offline
            Mazdak
            wrote on last edited by
            #5

            My date is like this: 2016-02-07 ( YYYY-MM-DD )

            Mazy
            "This chancy chancy chancy world."

            1 Reply Last reply
            0
            • K Keith Barrow

              AFAICT it should - people seem to have problems parsing the date in the first place. I'd put a breakpoint on/after this line:

              var myday = new Date(element.value) ;

              myday will probably be different across the OSs (and possibly browsers). You might be better off splitting element.value yourself and using the constructor function Date (_year, month, day_)

              KeithBarrow.net[^] - It might not be very good, but at least it is free!

              M Offline
              M Offline
              Mazdak
              wrote on last edited by
              #6

              Thanks I will try that and see what happen :)

              Mazy
              "This chancy chancy chancy world."

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups