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 Like 37 Dislike
Previous forums Next forums
Other forums

Search in the PHP Files
have to search asterisk(*) in the php code of the php files .
In the html page one text box

an interesting question
Greetings folks, got to ask an interesting question...

let say
i have created a function s

Delete HTML file after loading
I have limited experience with php and its been a year or two since I've last used it. I have a sma

PHP Array quick help
I need

$_SESSION{'username'} to be like this:


if $_SESSION['username'] = "gay

Two fgetcsv related questions ;D
First of im trying to get a file from a merchants server but the directory is protected, I know the

pls clear my confusion
Hi friends,

Pls solve my query .

what is the exact use of Scope Resolution Operator( i

Ajax Error since Upgrading to 3.5
Ever since upgrading my site to .NET 3.5 (I needed LINQ), I've been getting this annoying error on o

newbie question about multiple queries
hi everyone,
I'm sorry to ask such a basic question, but I'm young and trying to learn php on my

mysql query with single quotes in a variable
$sitedetails = "INSERT INTO vars (address, sitename, description, ownername, theme) VALUES ('$u

Multiple submit forms inside a mysql array page
Hi all,

Im having trouble to get the beneath script to work the thing i can't seem to get wor

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash