Connecting Tech Pros Worldwide Forums | Help | Site Map

Formatting a Date Stamp on Echo

RT
Guest
 
Posts: n/a
#1: Jul 17 '05
How would I format a timestamp which is used to show when a quote was
created in a record set.

This is the echo -
<?php echo($row_rsquote['created']); ?>

I tried doing this -
<?php echo date('D, m/d/Y',$row_rsquote['created']); ?>

but all I get is Monday, 01/18/2038.

Can anyone tell me how I can echo the value in the correct date format ?

Thanks


Pedro Graca
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Formatting a Date Stamp on Echo


RT wrote:
[Please don't send MIME encoded messages. Thank you]
[color=blue]
> How would I format a timestamp which is used to show when a quote was
> created in a record set.
>
> This is the echo -
> <?php echo($row_rsquote['created']); ?>
>
> I tried doing this -
> <?php echo date('D, m/d/Y',$row_rsquote['created']); ?>
>
> but all I get is Monday, 01/18/2038.
>
> Can anyone tell me how I can echo the value in the correct date format ?[/color]

A TIMESTAMP returns from MySQL as, eg, "20040512171115".
You cannot apply that to the PHP date() function (or you can, but the
results are not what you expect :) ).


I'd return a UNIX_TIMESTAMP from the database instead:

select fld1, fld2, UNIX_TIMESTAMP(created) as created, fld4
from table
...


which returns something that PHP interprets correctly, sparing you the
trouble to convert the timestamp in PHP.



--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Tim Van Wassenhove
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Formatting a Date Stamp on Echo


In article <BCC7BD52.150B0%robertth@comcast.net>, RT wrote:[color=blue]
> I tried doing this -
><?php echo date('D, m/d/Y',$row_rsquote['created']); ?>
>
> but all I get is Monday, 01/18/2038.[/color]

You could also leave the formatting to mysql.
Lookup the DATE_FORMAT function in the mysql manual for more info...


--
http://home.mysth.be/~timvw
Closed Thread