Jump to content

Help with dates and time.


takn25

Recommended Posts

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.

Link to comment
Share on other sites

<?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;

?>

Link to comment
Share on other sites

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() )

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.