MySQL timestamp to desired date function

This is a discussion on MySQL timestamp to desired date function within the PHP General forums, part of the PHP Programming Forums category; Hi all, I have a a timestamp in a DB (14 digits) that I want to display like I want ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-18-2003
Cesar Aracena
 
Posts: n/a
Default MySQL timestamp to desired date function

Hi all,

I have a a timestamp in a DB (14 digits) that I want to display like I
want in my pages. I tried to use strtotime, mktime and date functions
with no success... it always return the current timestamp instead of the
one I have stored. This is what I've done so far:

for ($x = 0; $x < $num_rows; $x++)
{
$row = mysql_fetch_array($result);
$date1 = strtotime($row[lugar_lastinsert]);
$date2 = date("d \de m \de Y \a \l\a\s H:i:s",
mktime($date1));
echo "<tr>";
echo "<td>";
echo $row[lugar_name]." - ".$row[lugar_specific];
echo "</td>";
echo "<td align=\"center\">";
echo $date2;
echo "</td>";
echo "</tr>";
}

How can I do this and make it work?

Thanks in advanced,

Cesar Aracena
www.icaam.com.ar
Reply With Quote
  #2 (permalink)  
Old 09-18-2003
Tom Rogers
 
Posts: n/a
Default Re: [PHP] MySQL timestamp to desired date function

Hi,

Thursday, September 18, 2003, 2:38:50 PM, you wrote:
CA> Hi all,

CA> I have a a timestamp in a DB (14 digits) that I want to display like I
CA> want in my pages. I tried to use strtotime, mktime and date functions
CA> with no success... it always return the current timestamp instead of the
CA> one I have stored. This is what I've done so far:

CA> for ($x = 0; $x < $num_rows; $x++)
CA> {
CA> $row = mysql_fetch_array($result);
CA> $date1 = strtotime($row[lugar_lastinsert]);
CA> $date2 = date("d \de m \de Y \a \l\a\s H:i:s",
CA> mktime($date1));
CA> echo "<tr>";
CA> echo "<td>";
CA> echo $row[lugar_name]." - ".$row[lugar_specific];
CA> echo "</td>";
CA> echo "<td align=\"center\">";
CA> echo $date2;
CA> echo "</td>";
CA> echo "</tr>";
CA> }

CA> How can I do this and make it work?

CA> Thanks in advanced,

CA> Cesar Aracena
CA> www.icaam.com.ar


strtotime() returns a timestamp so you don't need the mktime() call

$date2 = date("d \de m \de Y \a \l\a\s H:i:s", $date1);
--
regards,
Tom
Reply With Quote
  #3 (permalink)  
Old 09-18-2003
David Robley
 
Posts: n/a
Default Re: MySQL timestamp to desired date function

In article <001001c37d9e$c8d78c60$0300a8c0@notebook>, lists@icaam.com.ar
says...
> Hi all,
>
> I have a a timestamp in a DB (14 digits) that I want to display like I
> want in my pages. I tried to use strtotime, mktime and date functions
> with no success... it always return the current timestamp instead of the
> one I have stored. This is what I've done so far:
>
> for ($x = 0; $x < $num_rows; $x++)
> {
> $row = mysql_fetch_array($result);
> $date1 = strtotime($row[lugar_lastinsert]);
> $date2 = date("d \de m \de Y \a \l\a\s H:i:s",
> mktime($date1));
> echo "<tr>";
> echo "<td>";
> echo $row[lugar_name]." - ".$row[lugar_specific];
> echo "</td>";
> echo "<td align=\"center\">";
> echo $date2;
> echo "</td>";
> echo "</tr>";
> }
>
> How can I do this and make it work?
>
> Thanks in advanced,
>
> Cesar Aracena
> www.icaam.com.ar
>

Have you considered using MySQL's DATE_FORMAT function?

Cheers
--
Quod subigo farinam

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet?
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:22 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0