I have dates in the format yyyy-mm-dd hh:mm:ss
from the PHP date('Y-m-d H:i:s')
to fit in my mysqli database. I want it to be in these formats:
1) /*x hours ago*/ <span class="time">2014-02-24 10:38:19</span>
2) /*Yesterday*/ <span class="time">2014-02-23 16:38:19</span>
3) /*Feb 22nd*/ <span class="time">2014-02-22 16:38:19</span>
4) /*2013 Feb 22nd 16:38*/ <span class="time">2013-02-22 16:38:19</span>
I am using the plugin jquery-dateFormat and I have done this. Which gets each individual one into the correct format:
if ("<?php echo $date ?>" === $.format.date($('.time').html(), "yyyy-MM-dd") || "<?php echo $yesterday ?>" === $.format.date($('.time').html(), "yyyy-MM-dd")) {
$('.time').html($.format.prettyDate($('.time').html()));
} else if ("<?php echo $year ?>" !== $.format.date($('.time').html(), "yyyy")) {
$('.time').html($.format.date($('.time').html(), "MMM D - yyyy"));
} else {
$('.time').html($.format.date($('.time').html(), "MMM D"));
}
An example html document:
<span class="time">2014-02-24 10:38:19</span> <p>
<span class="time">2014-02-23 16:38:19</span> <p>
<span class="time">2014-02-22 16:38:19</span> <p>
<span class="time">2013-02-22 16:38:19</span> <p>
I want the output of this to be:
x hours ago
Yesterday
Feb 22nd
Feb 22nd - 2013
Currently the code above this will only format the first time
not all of them?