1

I want to remove 12:00:00 AM from following string.

<div class="modal-body">
    <p>1/11/2016 12:00:00 AM - 1/13/2016 12:00:00 AM</p>
</div>

The results should be:

1/11/2016 - 1/13/2016

How can I remove just the 12:00:00 AM from complete string all occurrences of it.

$('.modal-body > p').text().remove("12:00:00 AM");
2
  • If you are getting these time stamps from a database you may want to format them using either SQL or your server-side script. Commented Nov 30, 2015 at 17:27
  • @PeterKA you are right I need a quick fix for now. I will ask a separate question for that. Thanks a lot Commented Nov 30, 2015 at 17:36

1 Answer 1

7

You could use the .replace() method:

Example Here

$('.modal-body > p').text(function () {
    return $(this).text().replace(/12:00:00 AM/g, '');
});

Result:

<div class="modal-body">
    <p>1/11/2016  - 1/13/2016</p>
</div>

If you only want to replace the first occurrence, just remove the g flag.

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.