I want to strip out everything before the first “- ” and everything after the ” -” so I am left with “Dec 25, 2011” below (dates are dynamic so it always wont be Dec 25, 2011). I need to have a Javascript variable first:
Here is the html:
<p class="review-rating">
By oakbarrels
- Dec 25, 2011
-
Something.com
</p>
Here is the javascript variable I want to strip out “Dec 25, 2011”:
var thedate = $(this).find('.review-rating').html();
With “Dec 25, 2011” in a variable I would like to now use pHp strtotime to format it to “12/25/2011”.
To get the date string with Javascript, you can do something like this in jQuery:
You can see a jsFiddle of this here: http://jsfiddle.net/w2HvA/
Once this date string is passed to PHP you can use the following to format it.