justwannapost Posted December 19, 2007 Share Posted December 19, 2007 I have created a database in mysql called 'buildings'. Next to the name and cost i also have a need for a time to complete a building. Thus i inserted a 'time' field in mysql (HH-MM-SS). Now i wanted to know how i can tell php to interpretate it as a time. And once i know that i want to know how i can store it back in mysql (i have a script to compare times). Thanks for the answer in advance Greetz justwannapost Quote Link to comment Share on other sites More sharing options...
revraz Posted December 19, 2007 Share Posted December 19, 2007 I've found that the easiest way to handle date and time is with Unix timestamps. The date () function is so easy to work with that once you start using it, you wont use anything else. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 19, 2007 Share Posted December 19, 2007 <?php $time = time(); // timestamp $today = date("y-m-d h:i:s",$time); // print date in time format. ?> Use TIMESTAMP for the 'time' field. Quote Link to comment Share on other sites More sharing options...
taith Posted December 19, 2007 Share Posted December 19, 2007 and from the time(); you can also $time=strtotime("NOW - 1 month"); echo date("y-m-d h:i:s",$time); since starting into timestamps, i use them for most of everything :-) 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.