Skip to content Skip to sidebar Skip to footer

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() {

Solution 1:

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]
})

Solution 2:

$(document).on("change", "#select_date", function() {
  const at = $('#select_date :selected').text()

  //extract date
  const attend_date = at.split(' ')[0]
  //extract time
  const attend_time = at.split(' ')[1]
})

Post a Comment for "Extract Date From Text"