Jump to content

Recommended Posts

Hmm sorry i posted my problem wrongly

 

what i want to show is that how much time is left before his file will be deleted .

 

like this

 

$a = fileupload time + 8 hours;

$b = date("H:i:s");

 

and then $c= $a - $b;

 

echo $c;

 

 

but it shows only just numbers. how to solve this,

Link to comment
https://forums.phpfreaks.com/topic/244530-php-date-problem/#findComment-1256043
Share on other sites

Thats ok . but what i want to show is how much is left. so it would look like

 

$ftime= date("H:i:s", $file["date"],strtotime("+8hours")); // $file['time'] = file uploaded time

 

$ctime = $ftime - date("H:i:s");

 

echo $ctime;

 

but it gives error  a paramiter error

Link to comment
https://forums.phpfreaks.com/topic/244530-php-date-problem/#findComment-1256050
Share on other sites

What exactly do you have inside the variable $file["date"]? A UNIX timestamp or a string like SQL DATETIME ('YYYY-MM-DD HH:MM:SS') or what? I have a feeling you might need to calculate the time what is left manually or using DateTime functions (DateTime usage requires php >= 5.3 though, which would be probably the easiest way).

Link to comment
https://forums.phpfreaks.com/topic/244530-php-date-problem/#findComment-1256071
Share on other sites

Here is something to get you started, you need to calculate the time left to the expiration from the interval value (which is in seconds).

 

$timeStampFromDb = '1313089928';
$hoursToAdd = 8*60*60; // 8 hours 
$expireTime = $timeStampFromDb + $hoursToAdd; // time when 8 hours is added to the time from db
$now = mktime(); // time at the moment
$interval = $expireTime - $now; // if this is negative, time has expired
echo 'Time now: ' . date('Y:m:d H:i:s', $now) . '<br>'; // time now formatted
echo 'Expire time: ' . date('Y:m:d H:i:s', $expireTime) . '<br>'; // expire time formatted

Link to comment
https://forums.phpfreaks.com/topic/244530-php-date-problem/#findComment-1256101
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.