Jump to content

PHP date problem


mssakib

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.