Forums

PHP

This topic is locked

Problem with updating the timestamp

Posted 12 Jan 2002 22:53:41
1
has voted
12 Jan 2002 22:53:41 Thorsten Roever posted:
Hi there,

in my news-page I display the date a news was posted (using an 8-number-timestamp in mySQL and UD / Phakt). Okay, that went correctly and the date is shown correctly, too, but now my problem:

if the news was posted first on e.g. 07.01.2002 and I update that written news on 09.01.2002, the date from first posting switches automatically to the 09.01.2002

Is there a code to forbit that date-updating? I need a very simple help, because Newbie <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

My code to display the date is that:

&lt;?php

$t=$myNews-&gt;Fields("date";

$tag=substr($t, 6, 2);
$monat=substr($t, 4, 2);
$jahr=substr($t, 0, 4);

$dasdatum=$tag.".".$monat.".".$jahr;
echo "$dasdatum";

?&gt;

Replies

Replied 13 Jan 2002 16:47:41
13 Jan 2002 16:47:41 Bruno Mairlot replied:
The TIMESTAMP field is specifically designed to update automatically when you update the row.

Instead, if you want to have control over the date, then, use a DATE field. All mysql date and time function work either on the TIMESTAMP or the DATE field so choose the one which suits you the best.

--- Better to die trying, than never try at all ---
Replied 14 Jan 2002 12:46:51
14 Jan 2002 12:46:51 Thorsten Röver replied:
I Think so, Maehdros,

but I don't know how to set the right PHP to display my date like this e.g:

13.02.2002 (Germany)

Is there something in the mySQL I have to edit, too?

Replied 14 Jan 2002 13:20:19
14 Jan 2002 13:20:19 Bruno Mairlot replied:
Well, basically, you have two choices :

1. Format the date right in your SQL query, using the mysql-specific function like (month(), year(), dayofmonth(),...)

2. Format the date in PHP after receiving your date.

The option you choose depends on how familiar you are with SQL and/or PHP.

Personnaly, I prefer to use the first choice, though I wouldn't really recommend it (even if it is faster). (www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#Date_and_time_functions)

My suggestion is that you convert the date in MySQL into a unix timestamp, with the MySQL function UNIX_TIMESTAMP (for example : SELECT ID,UNIX_TIMESTAMP(date) FROM mytable)

Then use the date function from PHP using this timestamp. This will probably give much flexibility. (www.php.net/manual/en/ref.datetime.php)

--- Better to die trying, than never try at all ---

Reply to this topic