boylesg Posted February 24, 2014 Share Posted February 24, 2014 var dateEOW = new Date();dateEOW.setFullYear(2014);dateEOW.setMonth(3);dateEOW.setDate(1);alert(dateEOW); I give up! Why can't I change the value of a date object with the setDate(...) etc. These functions seem to have no effect and alert(...) simply outputs the current date. Link to comment Share on other sites More sharing options...
boylesg Posted February 24, 2014 Author Share Posted February 24, 2014 Actually if I do alert(dateEOF.getDay()) then I get the value I expect, however toDateString() still returns the current system date. Further getDay() function returns the day of the week for the current system date rather than the date that I have set using setDate(...) etc What the ###### is going on with this date object??? Is there some other function you have to call after using setDate(...) etc to make the internals of the object consistent?????? Link to comment Share on other sites More sharing options...
boylesg Posted February 24, 2014 Author Share Posted February 24, 2014 Either that or getDay() is simply calculating the wrong value for what ever reason. I am entering 1/3/2014 and according to getDay(), after setDate(1) setMonth(3) setYear(2014), the day of the week is 2 which is simply not correct. Link to comment Share on other sites More sharing options...
boylesg Posted February 24, 2014 Author Share Posted February 24, 2014 Bloody ###### it would seem to be a whole lot easier to do away with the php date object and simply calculate the day of week myself manually with function. Link to comment Share on other sites More sharing options...
Ingolme Posted February 24, 2014 Share Posted February 24, 2014 You can set the date with the constructor. I don't see where you're having a problem, though. var d = new Date(2014, 3, 1); Be aware that months are numbered from 0 to 11, so 3 would be April. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 24, 2014 Share Posted February 24, 2014 This is Javascript, not PHP. I'll move the thread. Link to comment Share on other sites More sharing options...
davej Posted February 25, 2014 Share Posted February 25, 2014 Either that or getDay() is simply calculating the wrong value for what ever reason. I am entering 1/3/2014 and according to getDay(), after setDate(1) setMonth(3) setYear(2014), the day of the week is 2 which is simply not correct. The day of the week for April 1 is indeed 2. The method getDay returns 0-6. Similarly getMonth returns 0-11. http://www.w3schools.com/jsref/jsref_getday.asp Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now