admin管理员组文章数量:1391974
the 1 st one which get using the id has format
var checkindate = $('#check-in').text();
28-07-2011
then i get the current date using
var now = new Date();
and it has the format
Wed Jul 20 2011 19:09:46 GMT+0530 (IST)
i want to get the date difference from these two dates . in this case it is 8 . i searched a lot and could not find an answer , please help....... :'(
the 1 st one which get using the id has format
var checkindate = $('#check-in').text();
28-07-2011
then i get the current date using
var now = new Date();
and it has the format
Wed Jul 20 2011 19:09:46 GMT+0530 (IST)
i want to get the date difference from these two dates . in this case it is 8 . i searched a lot and could not find an answer , please help....... :'(
Share Improve this question edited Jul 20, 2011 at 14:13 Curtis 103k69 gold badges277 silver badges359 bronze badges asked Jul 20, 2011 at 13:43 Kanishka PanamaldeniyaKanishka Panamaldeniya 17.6k31 gold badges127 silver badges195 bronze badges2 Answers
Reset to default 5You can parse the initial date, feed it to a date object, substract it with the current time to get a millisecond difference, and then divide it by the number of milliseconds in a day.
var checkindatestr = "28-07-2011";
var dateParts = checkindatestr.split("-");
var checkindate = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]);
var now = new Date();
var difference = now - checkindate;
var days = difference / (1000*60*60*24);
alert(days);
At the time of writing this gives -7.5. It's a negative number because the date is in the future. If you want a positive number, just swap the variables in the substraction. If you want a round number, just use Math.round.
You can parse your first date as described in this thread: Parse DateTime string in JavaScript
var strDate = "28-07-2011";
var dateParts = strDate.split("-");
var date = new Date(dateParts[2], (dateParts[1] - 1) ,dateParts[0]);
And then pare the two dates as asked here: Compare two dates with JavaScript
本文标签: phphow to compare two dates in jqueryStack Overflow
版权声明:本文标题:php - how to compare two dates in jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744666554a2618566.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论