Date Format : One 4 All
Parikesit <[email protected]> 28 Aug 2003 01:59:02 -0000
| Newsgroups | gmane.comp.web.oscommerce.tips |
|---|---|
| Message-ID | <5fb71075ce37a82d0da6f4d035f6c43d@osCommerce-Forums> |
This message was sent from: Tips and Tricks
http://forums.oscommerce.com/viewtopic.php?p=220746#220746
----------------------------------------------------------------
By default OsC have two functions to format a date:
[quote]tep_date_long($raw_date) => [color=red]Thursday 28 August, 2003[/color]
tep_date_short($raw_date) => [color=red]08/28/2003[/color]
[/quote]
that stored in includes/functions/general.php.
So how to format an other date?
We should make a new function. But how if we need many date format?so... we should make a new more flexible function to format a date, that can give any date format we want. We call it: [color=blue]tep_date_format()[/color].
I just make litle modification to default function, like below:
[size=9][i](store it in file general.php) [/i][/size]
[code] function tep_date_format($date_format, $raw_date) {
if ( ($raw_date == '0000-00-00 00:00:00') || ($raw_date == '') ) return false;
$year = (int)substr($raw_date, 0, 4);
$month = (int)substr($raw_date, 5, 2);
$day = (int)substr($raw_date, 8, 2);
$hour = (int)substr($raw_date, 11, 2);
$minute = (int)substr($raw_date, 14, 2);
$second = (int)substr($raw_date, 17, 2);
return strftime($date_format, mktime($hour,$minute,$second,$month,$day,$year));
}
[/code]
We can call this function anywhare ion our catalog:
[quote]tep_date_format(DATE_FORMAT_LONG, 'AnyTimeStamp') => [color=red]Thursday 28 August, 2003[/color]
tep_date_format(DATE_FORMAT_SHORT, 'AnyTimeStamp') => [color=red]08/28/2003[/color]
tep_date_format('%A', 'AnyTimeStamp') => [color=red]Thursday[/color]
tep_date_format('%d', 'AnyTimeStamp') => [color=red]28[/color]
tep_date_format('%m', 'AnyTimeStamp') => [color=red]08[/color]
tep_date_format('%B', 'AnyTimeStamp') => [color=red]August[/color]
tep_date_format('%Y', 'AnyTimeStamp') => [color=red]2003[/color]
:idea: to see another strftime() format, see: http://www.php.net/strftime
tep_date_format('%B - %Y', 'AnyTimeStamp') => [color=red]August - 2003[/color]
tep_date_format('%B - %Y', 'AnyTimeStamp') => [color=red]August - 2003[/color]
[/quote]
So, now we can remove 2 functions above indeed.