takn25 Posted January 31, 2011 Share Posted January 31, 2011 Hi, I have a created comment system, now what i am after is when the comment is posted the time is posted in hidden format. All is going fine but what i don't know, what should the time be posted as example date(H:m:s) or... the result i want is time in minutes first e.g. commented 2 mins ago and increasing to hours after that days. Could some one kindly guide me in the right directions. Quote Link to comment https://forums.phpfreaks.com/topic/226215-help-with-dates-and-time/ Share on other sites More sharing options...
suma237 Posted January 31, 2011 Share Posted January 31, 2011 <?php $date = '31-01-2011'; $beggin_hour = '13:30'; $end_hour = '14:00'; // Hours define("SECONDS_PER_HOUR", 60*60); // Calculate timestamp $start = strtotime($date." ".$beggin_hour); $stop = strtotime($date." ".$end_hour); // Diferences $difference = $stop - $start; // Hours $hours = round($difference / SECONDS_PER_HOUR, 0, PHP_ROUND_HALF_DOWN); # // Minutes $minutes = ($difference % SECONDS_PER_HOUR) / 60; echo $hours. ":" .$minutes; ?> Quote Link to comment https://forums.phpfreaks.com/topic/226215-help-with-dates-and-time/#findComment-1167766 Share on other sites More sharing options...
suma237 Posted January 31, 2011 Share Posted January 31, 2011 refer this link http://www.gidnetwork.com/b-16.html Quote Link to comment https://forums.phpfreaks.com/topic/226215-help-with-dates-and-time/#findComment-1167767 Share on other sites More sharing options...
Pikachu2000 Posted January 31, 2011 Share Posted January 31, 2011 If the time will be stored in a database, use the native format; typically YYYY-MM-DD HH:MM:SS, and store it in a field meant to hold date/time data. Then format it how you want it when you display it. If you're using MySQL, storing the date/timestamp is as simple as using NOW() as the value in the query string. INSERT INTO `table` (`timestamp_field`) VALUES ( NOW() ) Quote Link to comment https://forums.phpfreaks.com/topic/226215-help-with-dates-and-time/#findComment-1167913 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.