strtotime issue
Posted on
16th Feb 2014 07:03 pm by
admin
Hey all,
I'm playing around with some code, and basically the idea is:
Person changes their profileI fetch some XML that has a unix timestamp for the time the person changed their profile, so it'll keep increasing everytime I fetch the XML. It looks like this: <profileTime>12086</profileTime>I then run it through a function to convert the unix time to hours:mins:secsFinally I run it through another function to calc how long in the past that was, so it can be displayed in a user friendly format.
The issue is, every time I run it through the second function, the final displayed time keeps increasing, rather than staying the same, which it should stay the same, because the person only changed their profile once, at that original time.
Here is the first function, where I convert the unix time to h:m:s:
Code: function convert($sec, $padHours = false) {
$hms = null;
$hours = intval(intval($sec) / 3600);
$hms .= ($padHours) ? str_pad($hours, 2, "0", STR_PAD_LEFT). ':' : $hours. ':';
$minutes = intval(($sec / 60) % 60);
$hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':';
$seconds = intval($sec % 60);
$hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);
return $hms;
}
And here's the code in teh second function to format it:
Code: function olddate($hours, $minutes, $seconds) {
/* List of working timezones here:
*
* http://www.php.net/manual/en/timezones.php
*/
date_default_timezone_set('America/Chicago');
// Calculate the exact day and time the status message was set
$pf_time = strtotime("-".$hours." hours ".$minutes." minutes ".$seconds." seconds");
echo date("D F j, Y, g:i (s) a", $pf_time);
//return date("D F j, Y, g:i (s) a", $pf_time);
}
Anyone able to offer any advice?
No comments posted yet
Your Answer:
Login to answer
97
37
Other forums
Displaying Site Logo/Icon on a Title tag
really need some help out here. I want to insert a Logo/Icon just like the one close to the "PH
Modal Popup Help
Hi guys, I have a modal popup with an iframe. How can i send data from a label or textbox to the ifr
Code Review - SQL and Insertion Attacks (Warning: Not for Newbs)
Hey guys,
Its been a while, I know. Use to love coming here to answer peoples questions, but
Transform value 0 in no and 1 in yes help needed
Hello,
I have this in the table: "value" type int 0 to represent false and 1 to represe
how to read and write into a word document using php...?
hi,
I need,reading and writting into a word document using php.
Thank u inadva
difference between datetimes
($row['totime']-$row['fromtime'])/60
this is giving me 0
example of totime and fromtim
error checking breaking my code
Hi there, OK first of all, big apologies for what I assume is really fundamental errors in the struc
Weird MySQL error, why am I recieving this?
PHP Code:
<?php require "global_settings.php"; ?>
<titl
Why doesn't this work? (SSH2)
This is my script:
Code: <?php
$connection = ssh2_connect('213.251.167.109', 22);
Sort a two dimensional array.
Hi. I've set up a two dimensional array that reads as follows:
Code: $modifiedData = array(