Saffor Saffor - 1 year ago 129
jQuery Question

Extract date from text

I'm using this code to extract date from text without time. Is there any method to extract date without time and vice versa?

$(document).on("change", "#select_date", function() {
const at = $('#select_date :selected').text()
//2016-03-26 15:22:02
const attend_date = at.substring(0,10)
});

Answer Source

You can split() the date by space and select the first part:

$(document).on("change", "#select_date", function() {
  const at = $('#select_date :selected').text()
  const attend_date = at.split(' ')[0]
})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download