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. Link to comment https://forums.phpfreaks.com/topic/45266-datestimes/ 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. Link to comment https://forums.phpfreaks.com/topic/45266-datestimes/#findComment-219788 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. Link to comment https://forums.phpfreaks.com/topic/45266-datestimes/#findComment-219868 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 Link to comment https://forums.phpfreaks.com/topic/45266-datestimes/#findComment-219869 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. Link to comment https://forums.phpfreaks.com/topic/45266-datestimes/#findComment-219870 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') Link to comment https://forums.phpfreaks.com/topic/45266-datestimes/#findComment-219907 Share on other sites More sharing options...
Mutley Posted April 2, 2007 Author Share Posted April 2, 2007 Anyone? ??? Link to comment https://forums.phpfreaks.com/topic/45266-datestimes/#findComment-220053 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... Link to comment https://forums.phpfreaks.com/topic/45266-datestimes/#findComment-220056 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. Link to comment https://forums.phpfreaks.com/topic/45266-datestimes/#findComment-220105 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... Link to comment https://forums.phpfreaks.com/topic/45266-datestimes/#findComment-220127 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? Link to comment https://forums.phpfreaks.com/topic/45266-datestimes/#findComment-220172 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. Link to comment https://forums.phpfreaks.com/topic/45266-datestimes/#findComment-220186 Share on other sites More sharing options...
Mutley Posted April 3, 2007 Author Share Posted April 3, 2007 ??? Link to comment https://forums.phpfreaks.com/topic/45266-datestimes/#findComment-220521 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.