Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove time from a date/time string using jQuery

What is an efficient way to strip the time from this returned dataset using jQuery? I need the time to exist in the database because of ordering purposes however I need to display only the date.

<adopt_date>Apr 25 2013 2:41PM</adopt_date> is an example of a result from my Web Service.

Here is how I currently usethe information if it helps:

var adopted_date = $(this).find('adopt_date').text();

Where $(this) is dataset.

Thanks!

like image 531
MrS1ck Avatar asked Jun 12 '26 01:06

MrS1ck


2 Answers

Try this:

$("adopt_date").html(function (index, value) {
    return value.replace(/\d{1,2}:\d{2}(AM|PM)/ig, '');
});

FIDDLE

like image 199
palaѕн Avatar answered Jun 15 '26 00:06

palaѕн


You can do this with plain JavaScript:

adopted_date = adopted_date.replace(/ [0-9]*[0-9]:[0-9][0-9]A*P*M/,'');

jsFiddle example

like image 38
j08691 Avatar answered Jun 15 '26 00:06

j08691



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!