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
Selecting an "empty" date formated field
How do you select an "empty" date field? I've tried the few ways I can think.
SQL> select
Batch Session SM35 stuck in status 'in Background
Hi Experts,
I am facing a problem with Batch Input session SM35.
The batch se
PHP code needed to get/post form fields and request mysql query results.
I'm new to PHP
I've created an html form to allow the user to request a basic telephone dire
PHP and XML image gallery variable issue
I'm trying to display the large image on the same page as the thumbnails, to do that I'm passing a v
EXplanation help
Hey all,
I am still fairly new to PHP programming and I am trying to put together a page wher
validating url
im trying to validate url's sent to me by a form
the url's im collecting are for placing banners
problem with php mysql query
Hi guy's...
I'm totally lost here..because don't have any idea how to make a query for grab r
Image loading
Hi Developers,
I'm trying to display an image from images/image.gif getting the url from mysq
Help: problem with Headers to download PDF file
Hi,
I'm trying to implement a script where when a user clicks a link he gets a PDF file to op
If a record matches an existing record do nothing
So I don't know if I should put this here or in mysql, but what my script is for is for people to ad