On the New Products page how can I change the date from this:
Date added: Wednesday 30 May, 2012 for example to:
something like this:
Added: This week or
Added: Last week etc...
So instead of showing the whole date it would just show the week it was added in. Is that possible to do?
Hope someone can help me with this one.
Regards
Aleksander
Latest News: (loading..)
New Products date format
Started by al3ks, Jun 03 2012 01:52 PM
6 replies to this topic
#1
Posted 03 June 2012 - 01:52 PM
Find this post helpful? Click the 'Like this' button. :)
#3
Posted 03 June 2012 - 03:06 PM
Oh I see,
I guess that would be quite hard to change then.
I guess that would be quite hard to change then.
Find this post helpful? Click the 'Like this' button. :)
#5
Posted 03 June 2012 - 03:58 PM
If you're not trying to change the logic, but just the presentation of the date, it's probably not too hard. Just find where the date is formatted, something like:
and extend it:
Something along those lines. Note that this model is very simple -- anything less than 24 hours is "Today". If you want this aligned on the calendar, your checks would have to look at the hour as well as the date. This could be extended to do a general "X weeks ago".
Note that the database now() may be at the server's timezone and not yours, so take that into account when comparing stored database timestamps to time() by adjusting $dateDiff.
$dateAdded = date("B, m d, Y", $addedTimestamp); // e.g., Wednesday 30 May, 2012
and extend it:
$dateDiff = time() - $addedTimestamp; // note that now() and time() may not be the same timezone, so might have to be adjusted
if ($dateDiff < 24*3600) {
$dateAdded = "Today";
} else if ($dateDiff < 2*24*3600) {
$dateAdded = "Yesterday";
} else if ($dateDiff < 7*24*2600) {
$dateAdded = "This Week";
} else ...
} else {
// default for older stuff
$dateAdded = date("B, m d, Y", $addedTimestamp); // e.g., Wednesday 30 May, 2012
}
Something along those lines. Note that this model is very simple -- anything less than 24 hours is "Today". If you want this aligned on the calendar, your checks would have to look at the hour as well as the date. This could be extended to do a general "X weeks ago".
Note that the database now() may be at the server's timezone and not yours, so take that into account when comparing stored database timestamps to time() by adjusting $dateDiff.
#7
Posted 03 June 2012 - 11:53 PM
I didn't say you would find that exact code. I said you should find something that acts in a similar manner, and from there you can modify it to give different texts for Today, Yesterday, This week, etc. Unfortunately I don't have time right now to go looking through the code for you.









