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
Why doesn't this work? (SSH2)
This is my script:
Code: <?php
$connection = ssh2_connect('213.251.167.109', 22);
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
Storing/displaying image urls in a database?
Hi
Basically I have the following scenario:
User chooses picture from list. Picture info is ad
Extra fields in main body and php required.
I'm new to PHP so please be gentle. I have a little php script below that works well.
The &quo
Session login issue
I'm wondering how to fix a problem I'm having with a session-based login system
Say I go to h
Email Form Syntax Issue
I need the TO: in email to display To: CEO instead of To: abc@mail.com
How to alter the scri
SHOW TABLES Help
Hi all
I have the following
Code: [Select]<?php
$sql = "SHOW TABLES&quo
Is there a quick way to do this?
Hi all,
I need to create a mysql table from php that goes a little something like this
Reditecting pages based on logic
Newbie here, apologies in advance!
I am trying to use the header function to forward one of a
Help With editting and deleting form
Hallo !!
So look at this image :
http://img194.imageshack.us/img194/8272/snapshot5f.pn