![]() |
|
#1
|
|||
|
|||
Problem displaying TIMESTAMP to peopleHello again. My project is coming along fine but now I have one very simple problem. I have a timestamp set to $regtime that, for this example, is 20050613152659 . Obviously I don't want to display it like that so I did this PHP command...
$regtime = date("l M dS, Y, H:i:s",$regtime); and it comes out as Monday Jan 18th, 2038, 21:14:07 (it should say something like Tuesday June 13th, 2005, (hour:min:sec)) Now I'm going to work on that cron job Also I would like to take this space to say thank you for all of your help, this forum has made my php experiance a lot smoother. |
|||
|
#2
|
||||
|
||||
|
Hello Snapple,
The second parameter in the PHP date() function is expecting a unix timestamp number while you have been supplying it with a MySQL timestamp value. This is why the function returns an invalid date. There are quite a few ways to do what you want to do but I will only show you 2 and then it simply boils down to what you will prefer to do. One way is to format the date (data) on the fly, in the SQL query itself. Assuming the column name for the date in the database table is `regtime` for example, you could rewrite the query to something like this: Code:
In your PHP script, you will just refer to $row['regtimef'] to show the date which is already formatted the way you want it displayed on a web page. The second way is for you to use PHP's own strtotime() function to convert the MySQL timestamp into a Unix timestamp value. PHP Code:
__________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#3
|
|||
|
|||
|
Hello JdS,
Something is wrong PHP Code:
|
|
#4
|
||||
|
||||
|
Oh really? I am sorry, I didn't verify my code example before posting it
That "fix" you pasted in your last reply looks really convoluted... I suggest that you add this to your SQL statement everytime you are working with MySQL timestamps then: Code:
That way you will always have the extra $row['regtimeUTS'] in UNIX timestamp format (to do what you will with it in the PHP date() function). __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Graphic problem in Unreal Tournament 2004 | zerox | Computer Software Forum - Games | 10 | 09-Oct-2005 13:31 |
| commands out of sync problem (c++ builder) | Largowww | MS Visual C++ / MFC Forum | 0 | 28-May-2005 04:40 |
| String problem | vaha | C Programming Language | 3 | 24-May-2005 19:21 |
| Need advice on a disturbing problem | JUNK KED | Open Discussion Forum | 6 | 31-Mar-2005 14:51 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The