Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

New Products date format


al3ks

Recommended Posts

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

Find this post helpful? Click the 'Like this' button. :)

Link to comment
Share on other sites

@@al3ks

 

When you add a product, the date entered is automatically added to the database. The current SQL queries look for that date. You would have to rewrite the queries and add an array to determine the output.

 

 

 

Chris

Link to comment
Share on other sites

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:

$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.

Link to comment
Share on other sites

@@MrPhil

 

I cannot find a code like this:

 

$dateAdded = date("B, m d, Y", $addedTimestamp);

 

The file I want to make the change in is: catalog/products_new.php

Find this post helpful? Click the 'Like this' button. :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...