Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
121
rated 0 times [  126] [ 5]  / answers: 1 / hits: 15474  / 7 Years ago, wed, october 25, 2017, 12:00:00

I need to convert an <input type="date"> value in a timestamp. This is my HTML code:


 <input type="date" name="date_end" id="date_end">

This field has a value that I have put like 25/10/2017


My jQuery code is:


var dataEnd = $('[name="date_end"]').val();
if (!dataEnd) {
return false;
} else {
var timestamp_end=$('[name="date_start"]').val().getTime();
console.log("TIMESTAMP END "+timestamp_end);
.....
}

But this is not working... why not?


More From » html

 Answers
16

make a new Date() passing the value of your input as parameter, then call getTime(). here an example:





$('[name=date_end]').on('change',function() {
var dataEnd = $(this).val();
console.log((new Date(dataEnd)).getTime());
})

<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>
<input type=date name=date_end id=date_end>




[#56125] Sunday, October 22, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tobyl

Total Points: 598
Total Questions: 110
Total Answers: 114

Location: Vietnam
Member since Sat, Feb 12, 2022
2 Years ago
tobyl questions
Tue, Aug 10, 21, 00:00, 3 Years ago
Wed, Jan 13, 21, 00:00, 3 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
;