Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

turn timestamp into a human-friendly date string !!

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194
I found the following function to display the date i.e. 13 Jul 2002

The formatDate() function in the code above is a function wrote to turn a MySQL timestamp into a human-friendly date string:

functions.php:
--------------------------------------
function formatDate($val)
{
$arr = explode("-", $val);
return date("d M Y", mktime(0,0,0, $arr[1], $arr[2], $arr[0]));
}
--------------------------------------
display.php:
--------------------------------------
// includes
include("../functions.php");


// generate and execute query
$query = "SELECT field1, field2, timestamp FROM tablename ORDER BY timestamp DESC LIMIT 0, 5";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

// if records present
if (mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_object($result))
{
?>
<br>
<font size=&quot;-2&quot;><? echo formatDate($row->timestamp); ?></font>
<p>
--------------------------------------------

This display date in English, how to display it in other languages like Spanish?
 
For Spanish in particular, modify your function as follows:

[tt]
Code:
function formatDate ($val)
{
  $arr = explode(&quot;-&quot;, $val);
  setlocale(LC_TIME, &quot;es_ES&quot;);
  return strftime(&quot;%d %B %Y&quot;, mktime (0,0,0, $arr[1], $arr[2], $arr[0]));
}
[/tt]

Check the PHP online manual for more information on the setlocale() function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top