Time and Date
Moderator: General Moderators
Okay so if I have the two dates,
e.g. $currentDate = 2006-10-16
$postDate = 2006-10-17
$currentTime = 12:12:12
$postTime = 12:12:12
I effectively want to compare them together to get the amount of seconds between them. Have looked around for a function on php.net and cannot find one, is there a friendly way of doign this?
Obviosuly the outcome of this would be 86400 seconds (1 exact day(24 hours)).
Thanks..
e.g. $currentDate = 2006-10-16
$postDate = 2006-10-17
$currentTime = 12:12:12
$postTime = 12:12:12
I effectively want to compare them together to get the amount of seconds between them. Have looked around for a function on php.net and cannot find one, is there a friendly way of doign this?
Obviosuly the outcome of this would be 86400 seconds (1 exact day(24 hours)).
Thanks..
Im using the following code with printf's function as mentioned in this thread.
Here is my code:
$secondsElapsed = $currentUNIXTS - $subUNIXTS;
$secondsElapsed = tick_count($secondsElapsed);
echo $secondsElapsed;
It just prints the word Array when i try this, how do i get it to print the string or access directly elements of the array which contain the number of days, months, hours etc...
Here is my code:
$secondsElapsed = $currentUNIXTS - $subUNIXTS;
$secondsElapsed = tick_count($secondsElapsed);
echo $secondsElapsed;
It just prints the word Array when i try this, how do i get it to print the string or access directly elements of the array which contain the number of days, months, hours etc...
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
standard array access
Code: Select all
$array['elementName']
$array[3]The following code for working out the amount of time difference between now and a recent post does not work.
It gives a result but it is not correct, here is a screen shot of some output:
Date: 2006-10-16
Time: 16:57:21
Submitter: Test
Description:
Category: General
Array ( [years] => 0 [weeks] => 0 [days] => 0 [hours] => 04 [minutes] => 05 [seconds] => 02 )
This is obviously wrong since this was posted yesterday and I tried this just a moment ago!
This uses printf's function which is in the code snippets area of the forums..
Please help, Im at my wits end..!
It gives a result but it is not correct, here is a screen shot of some output:
Date: 2006-10-16
Time: 16:57:21
Submitter: Test
Description:
Category: General
Array ( [years] => 0 [weeks] => 0 [days] => 0 [hours] => 04 [minutes] => 05 [seconds] => 02 )
This is obviously wrong since this was posted yesterday and I tried this just a moment ago!
Code: Select all
//mktime(hour, minute, second, month, day, year);
//GET TODAYS DATETIME DETAILS...
$currentDay = date('d');
$currentMinute = date('i');
$currentHour = date('H');
$currentSecond = date('s');
$currentYear = date('Y');
$currentMonth = date('m');
//CREATE ME A UNIX TIMESTAMP OF THIS POINT IN TIME...
$currentUNIXTS = mktime($currentHour,
$currentMinute,
$currentSecond,
$currentMonth,
$currentDay,
$currentYear);
//GET DETAILS OF THE SUBMITTED TIME...
$subDate = explode('-',$row['date']);
$subTime = explode(':',$row['time']);
$subDay = $subDate[2];
$subMinute = $subTime[1];
$subHour = $subTime[0];
$subSecond = $subTime[2];
$subYear = $subDate[0];
$subMonth = $subDate[1];
//CREATE ME A UNIX TIMESTAMP OF SUBMISSION TIME FOR COMPARING...
$subUNIXTS = mktime($subHour,
$subMinute,
$subSecond,
$subMonth,
$subDay,
$subYear);
//OBTAIN TIME PASSED SINCE SUBMITTAL...
$secondsElapsed = $currentUNIXTS - $subUNIXTS;
$secondsArr = tick_count($secondsElapsed);
//echo $secondsElapsed['minutes']; DEFINITELY WORKS
abs($secondsArr);
print_r($secondsArr);Please help, Im at my wits end..!
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
simplifies totommy1987 wrote:Code: Select all
//mktime(hour, minute, second, month, day, year); //GET TODAYS DATETIME DETAILS... $currentDay = date('d'); $currentMinute = date('i'); $currentHour = date('H'); $currentSecond = date('s'); $currentYear = date('Y'); $currentMonth = date('m'); //CREATE ME A UNIX TIMESTAMP OF THIS POINT IN TIME... $currentUNIXTS = mktime($currentHour, $currentMinute, $currentSecond, $currentMonth, $currentDay, $currentYear);
Code: Select all
$currentUNIXTS = time();