0

I'm querying the timestamp from the field created in the table messages. My database table currently stands as..

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| msg_id |  messages | uid_fk | ip |   created   | uploads |
| 706    |  ........ |   39   | .. |  1368631445 |    0    |
| 717    |  ........ |   39   | .. |  1368640802 |    0    |
| 705    |  ........ |   39   | .. |  1368631238 |    0    |
| 696    |  ........ |   39   | .. |  1368595705 |    0    |
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

This is how I'm querying the timestamp from created.

public function Time_Stamp($uid){
    $res = mysql_query("SELECT created FROM messages WHERE uid_fk='$uid'");
    while ( $row = mysql_fetch_array($res) ) {
        echo date("g:i", strtotime($row["created"])) . "<br />";
    }
}

----- Output -----

  1. 9:00
  2. 9:00
  3. 9:00
  4. 9:00 So basically just printing out in a list the same time.

It's not printing their unique time from the created field. I'm not so perfect with MySQL but It has do to with their unique iD's(either msg_id, uid_fk) also, $uid equals the uid_fk, $uid is defined in another table.

How do I go about bringing their specific iD's to print out their correct timestamp.

1 Answer 1

1
echo date("g:i", $row["created"]);

strtotime turns a date string like 2013-05-15 22:35:00 into a timestamp.
date turns a timestamp into a readable date string.
You already have timestamps in the database, don't use strtotime.

Sign up to request clarification or add additional context in comments.

3 Comments

Sigh, so simple I appreciate it! What is a good way to use strtotime? Or where would be most correct place to use it?
There are two (commonly used) possible date representations: numeric timestamps and standardized formats like "2013-05-15 22:35:00". It's easy to do math on numeric timestamps and it's easier to read date strings. Use date and strtotime accordingly to turn one into the other as needed.
Great, now I understand it! Thank you for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.