Mutley Posted April 2, 2007 Share Posted April 2, 2007 I'm making a really basic forum. When users post I want it to say "Latest post: (TIME) (DATE)" in say 22:00, then date as DD/MM/YY When I insert it into the database do I want my field to be configured as "DATE" and a field configured as "TIME" or should I use VARCHAR? But I also noticed it doesn't insert it in DD/MM/YY, it does MM/DD/YY or something weird? To insert do I just do time() and date()? Thanks. Quote Link to comment Share on other sites More sharing options...
trq Posted April 2, 2007 Share Posted April 2, 2007 Use timestamps to store your dates, using a VARCHAR will prevent you be able to sort or search by date. Quote Link to comment Share on other sites More sharing options...
Mutley Posted April 2, 2007 Author Share Posted April 2, 2007 Ahh, that's good, has both time and date. 2007-04-02 10:57:14 How do I make it 02-04-2007? And also the time in GMT? I get the data from the database using $time as my variable. Quote Link to comment Share on other sites More sharing options...
only one Posted April 2, 2007 Share Posted April 2, 2007 it depends on the server time, if your servers set to the same time as GMT the time on your webstie will be aswell, visit http://uk2.php.net/date this will have all your date and time functions hope that solves your problem Quote Link to comment Share on other sites More sharing options...
trq Posted April 2, 2007 Share Posted April 2, 2007 Take a look at the date function and examples. Quote Link to comment Share on other sites More sharing options...
Mutley Posted April 2, 2007 Author Share Posted April 2, 2007 How do I format from the database though? If my field is "time" and it's a timestamp, in the SQL query do I do: DATE_FORMAT(time,'D M j G:i:s T Y') Quote Link to comment Share on other sites More sharing options...
Mutley Posted April 2, 2007 Author Share Posted April 2, 2007 Anyone? ??? Quote Link to comment Share on other sites More sharing options...
only one Posted April 2, 2007 Share Posted April 2, 2007 explain in more detail? if your serves forward an hour just minus 1 from the hour... Quote Link to comment Share on other sites More sharing options...
Mutley Posted April 2, 2007 Author Share Posted April 2, 2007 No that's nothing what I mean. In my database I have a field called "time" which is set to "timestamp" configuration. In my PHP file I want to display this so I have a SQL query that calls this field. What I want to know is how to format the field in my PHP file. Quote Link to comment Share on other sites More sharing options...
Mutley Posted April 2, 2007 Author Share Posted April 2, 2007 This is what I tried: // START NORMAL TOPICS: $sql = "SELECT topic_id, user_id, section_id, DATE_FORMAT(time,'D M j G:i:s T Y') AS times, sticky, title, content FROM bb_topics WHERE section_id = '$section' AND sticky = '0' ORDER BY topic_id DESC"; But doesn't work... Quote Link to comment Share on other sites More sharing options...
Mutley Posted April 2, 2007 Author Share Posted April 2, 2007 Fixed it, did: UNIX_TIMESTAMP(time) AS times $times = date("m-d-Y H:i:sa",$times); echo $times; But, how do I change my time zone to GMT? Quote Link to comment Share on other sites More sharing options...
Mutley Posted April 2, 2007 Author Share Posted April 2, 2007 With daylight savings, I did do: putenv("TZ=Europe/London"); But it doesn't consider time zones, it's 1 hour ahead. Quote Link to comment Share on other sites More sharing options...
Mutley Posted April 3, 2007 Author Share Posted April 3, 2007 ??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.