Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/311639-why-cant-i-get-the-day/
Share on other sites

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 by Hybris

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.

  • Great Answer 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.