javascript - jQuery date check using .now() -
thanks in advance.
i using below code remove table rows table based on date. table shows upcoming bookings include bookings same day in table , remove past bookings. if date before today hide row.
heres html.this part of loop way.
<table style="width:100%;" class="dashboard_widget" id="bookingsdashboard"> <thead> <tr> <th> <p><strong>booking ref</strong></p> </th> <th> <p><strong>arrival date</strong></p> </th> <th> <p><strong>booking type</strong></p> </th> <th> <p><strong>operator name</strong></p> </th> <th class="options"> <p><strong>options</strong></p> </th> </tr> </thead> <tbody> <tr> <td> <h3>mr design et al</h3> </td> <td id="arrivaldate-widget"> <p><span class="arrivaldate-widget-unix" style="display:none;">1434844800</span> 21.06.2015<br>(9 nights)</p> </td> <td> <p>corporate</p> </td> <td> <p>operatex</p> </td> <td> <a href="http://www.greenmonkeypublicrelations.com/scpads/wp-admin/post.php?post=225&action=edit"><i class="fa fa-file-text" style="padding-right:10px;"></i>edit</a> </td> </tr> <tr> <td> <h3>mr knopps</h3> </td> <td id="arrivaldate-widget"> <p><span class="arrivaldate-widget-unix" style="display:none;">1429574400</span> 21.04.2015<br>(343 nights)</p> </td> <td> <p>groups</p> </td> <td> <p>operatorsio</p> </td> <td> <a href="http://www.greenmonkeypublicrelations.com/scpads/wp-admin/post.php?post=219&action=edit"><i class="fa fa-file-text" style="padding-right:10px;"></i>edit</a> </td> </tr> <tr> <td> <h3>mr knopps</h3> </td> <td id="arrivaldate-widget"> <p><span class="arrivaldate-widget-unix" style="display:none;">1456012800</span> 21.02.2016<br>(297 nights)</p> </td> <td> <p>groups</p> </td> <td> <p>operatorsio</p> </td> <td> <a href="http://www.greenmonkeypublicrelations.com/scpads/wp-admin/post.php?post=220&action=edit"><i class="fa fa-file-text" style="padding-right:10px;"></i>edit</a> </td> </tr> <tr> <td> <h3>mr knopps</h3> </td> <td id="arrivaldate-widget"> <p><span class="arrivaldate-widget-unix" style="display:none;">1429574400</span> 21.04.2015<br>(6 nights)</p> </td> <td> <p>groups</p> </td> <td> <p>operatorsio</p> </td> <td> <a href="http://www.greenmonkeypublicrelations.com/scpads/wp-admin/post.php?post=218&action=edit"><i class="fa fa-file-text" style="padding-right:10px;"></i>edit</a> </td> </tr> </tbody></table> heres jquery
jquery(document).ready(function(){ var date = jquery('.arrivaldate-widget-unix').val(); var time = jquery.now(); if (date < time ) { jquery('.arrivaldate-widget-unix').closest('tr').hide(); } });
assuming need hide rows
you need use .each() iterate on object
jquery(document).ready(function(){ var time = jquery.now(); //or new date(jquery.now()) jquery('.arrivaldate-widget-unix').each(function(){ var date = jquery(this).val(); if (date < time ) { jquery(this).closest('tr').hide(); } }); }); edit, compare date part use
jquery(document).ready(function(){ var today = new date(); //only date part today.sethours(0, 0, 0, 0); jquery('.arrivaldate-widget-unix').each(function(){ var date = jquery(this).val(); if (date < today ) { jquery(this).closest('tr').hide(); } }); });
Comments
Post a Comment