Jump to content



Latest News: (loading..)

- - - - -

New Products date format


This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#-19   al3ks

al3ks
  • Members
  • 288 posts

Posted 03 June 2012 - 01:52 PM

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. :)

#-18 ONLINE   DunWeb

DunWeb

    The Censored One

  • Members
  • 12,825 posts

Posted 03 June 2012 - 01:55 PM

@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
:|: Was this post helpful ? Click the LIKE THIS button :|:

See my Profile to learn more about add ons, templates, support plans and custom coding (click here)

#-17   al3ks

al3ks
  • Members
  • 288 posts

Posted 03 June 2012 - 03:06 PM

Oh I see,
I guess that would be quite hard to change then.
Find this post helpful? Click the 'Like this' button. :)

#-16 ONLINE   DunWeb

DunWeb

    The Censored One

  • Members
  • 12,825 posts

Posted 03 June 2012 - 03:07 PM

@al3ks

No hard really, if you have the PHP skills and know osCommerce.  It is more time consuming.


Chris
:|: Was this post helpful ? Click the LIKE THIS button :|:

See my Profile to learn more about add ons, templates, support plans and custom coding (click here)

#-15   MrPhil

MrPhil
  • Members
  • 4,194 posts

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

#-14   al3ks

al3ks
  • Members
  • 288 posts

Posted 03 June 2012 - 08:12 PM

@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. :)

#-13   MrPhil

MrPhil
  • Members
  • 4,194 posts

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.