mssakib Posted August 11, 2011 Share Posted August 11, 2011 Hi Hi want to show my users a time which is after 8 Hours so i am using mktime like this <?php $after = mktime(8,0,0,date("m"),date("d"),date("Y")); echo "After 8 Hr is ".date("H:i:s", $after); ?> but it is showing something like 1313042400 So need help SaKIB Quote Link to comment https://forums.phpfreaks.com/topic/244530-php-date-problem/ Share on other sites More sharing options...
AyKay47 Posted August 11, 2011 Share Posted August 11, 2011 $after = date("H:i:s",strtotime("+8hours")); print "After 8 hours is $after"; Quote Link to comment https://forums.phpfreaks.com/topic/244530-php-date-problem/#findComment-1256041 Share on other sites More sharing options...
mssakib Posted August 11, 2011 Author Share Posted August 11, 2011 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, Quote Link to comment https://forums.phpfreaks.com/topic/244530-php-date-problem/#findComment-1256043 Share on other sites More sharing options...
AyKay47 Posted August 11, 2011 Share Posted August 11, 2011 refer to my updated post.. Quote Link to comment https://forums.phpfreaks.com/topic/244530-php-date-problem/#findComment-1256045 Share on other sites More sharing options...
mssakib Posted August 11, 2011 Author Share Posted August 11, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/244530-php-date-problem/#findComment-1256050 Share on other sites More sharing options...
TeNDoLLA Posted August 11, 2011 Share Posted August 11, 2011 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). Quote Link to comment https://forums.phpfreaks.com/topic/244530-php-date-problem/#findComment-1256071 Share on other sites More sharing options...
mssakib Posted August 11, 2011 Author Share Posted August 11, 2011 if i echo $file["date"]; it shows 1313089928 and another thing is how to calculate 3 time like date("d.m.Y H:i:s", $file["date"]) and strtotime("+8hours") Quote Link to comment https://forums.phpfreaks.com/topic/244530-php-date-problem/#findComment-1256085 Share on other sites More sharing options...
TeNDoLLA Posted August 11, 2011 Share Posted August 11, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/244530-php-date-problem/#findComment-1256101 Share on other sites More sharing options...
mssakib Posted August 11, 2011 Author Share Posted August 11, 2011 Thx worked. But it was using wrong delet time. But when i used date('H:i:s'); in lieu if mktime(); it worked. thx again Quote Link to comment https://forums.phpfreaks.com/topic/244530-php-date-problem/#findComment-1256108 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.