Hybris Posted October 24, 2020 Share Posted October 24, 2020 var etaDate = new Date(); etaDate = document.getElementById("etaDate").value; window.alert(etaDate); var day = etaDate.getDate(); window.alert(day); I have a form with some date inputfields. Now I need to check what day of the week a certain date is but I can't get the getDate() to return a value. The etaDate print out the correct date but alert(day) show nothing? Any ideas? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/311639-why-cant-i-get-the-day/ Share on other sites More sharing options...
Hybris Posted October 24, 2020 Author Share Posted October 24, 2020 I noticed it should be .getDay() but it is still not working.. Quote Link to comment https://forums.phpfreaks.com/topic/311639-why-cant-i-get-the-day/#findComment-1582036 Share on other sites More sharing options...
requinix Posted October 24, 2020 Share Posted October 24, 2020 What is "etaDate"? According to the code. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311639-why-cant-i-get-the-day/#findComment-1582037 Share on other sites More sharing options...
Hybris Posted October 24, 2020 Author Share Posted October 24, 2020 (edited) Wierd. Its working if I split etaDate into substrings and use them to set a new date? Anyone know why that works but not to just use it direcly? <input id="etaDate" class="inputClass" type="date" tabindex="5"> Edited October 24, 2020 by Hybris Quote Link to comment https://forums.phpfreaks.com/topic/311639-why-cant-i-get-the-day/#findComment-1582040 Share on other sites More sharing options...
requinix Posted October 24, 2020 Share Posted October 24, 2020 Try answering my question. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311639-why-cant-i-get-the-day/#findComment-1582041 Share on other sites More sharing options...
Hybris Posted October 24, 2020 Author Share Posted October 24, 2020 (edited) It should be a date I guess? In the inputfield I get a calendar where I can select a date and as I edited in above the type says date ^^ ? If I type in 2020-01-01 as a date that is also what the etaDate alertbox displays? eEDit:: Ahh so Im making it something else than date when i use .value? Edited October 24, 2020 by Hybris Quote Link to comment https://forums.phpfreaks.com/topic/311639-why-cant-i-get-the-day/#findComment-1582042 Share on other sites More sharing options...
requinix Posted October 24, 2020 Share Posted October 24, 2020 Let's take a closer look at the first two lines. var etaDate = new Date(); etaDate = document.getElementById("etaDate").value; On the first line, you set etaDate to be a new Date instance. On the second line you throw away that Date and instead get a value from some input. Does that seem weird? Also, the .value from a form field is always a string. Always. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311639-why-cant-i-get-the-day/#findComment-1582043 Share on other sites More sharing options...
Hybris Posted October 24, 2020 Author Share Posted October 24, 2020 Ahh ok thanks, is there another way of getting the value of a cell that returns the type too or is the type="" in html just for formatting the inputfield? Quote Link to comment https://forums.phpfreaks.com/topic/311639-why-cant-i-get-the-day/#findComment-1582045 Share on other sites More sharing options...
requinix Posted October 24, 2020 Share Posted October 24, 2020 Not that I know of. The value is a date. Feed it to Date and be done with it. Quote Link to comment https://forums.phpfreaks.com/topic/311639-why-cant-i-get-the-day/#findComment-1582046 Share on other sites More sharing options...
Hybris Posted October 24, 2020 Author Share Posted October 24, 2020 Ok great, this helped me fix some other minor issues in my code that I saved for a rainy day. Thank you soo much Quote Link to comment https://forums.phpfreaks.com/topic/311639-why-cant-i-get-the-day/#findComment-1582047 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.