2

I need to do a web-form. It must content a date filter, i.e. some items must be shown if its are created between one date and other date. My form:

<form id="tweetshow" method="post" action="" >
  <p>
    Enter user_id: <input type="text" name="user_id" />
  </p>
  <p>
    Enter user last tweets amount: <input type="text" name="last_tweets_amount" />
  </p>
  <p>
    From date: <input type="date" name = "from_date" step=7 min=2014-09-08>
  </p>
  <p>
    To date: <input type="date" name = "to_date" step=7 min=2014-09-08>
  </p>
  <p>
    <input type="button" value="Submit" onClick="ShowTweets()"/>
  </p>
</form>

This is my java-script, which proccesses it:

<script>
  var test = document.forms['tweetshow'].to_date.value;
  ...
  success:function(response)
  {
    ...
    if((item.created_at <= test))
    {
      $("<article>", { id: item.id })
      .append($header, $text, $details)
      .appendTo("#tweets");
      alert(test);
    }
  }
  ...
</script>

The variable "item.created_at" consists a date, which is built, for example, how this pattern: "Sun Oct 19 11:45:28 +0000 2014", but the date, which enters in form(it consists in variable "test"), builds as this pattern: "2014-10-19". How to compare the dates correctly?

1 Answer 1

1
var test = document.forms['tweetshow'].to_date.value;
test = new Date(test).getTime();

Convert to date object

if((new Date(item.created_at).getTime() <= test))
    {
      // Do something
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.