redarrow Posted March 19, 2006 Share Posted March 19, 2006 How can i work out the time remaning from my time varablesplease help me,How to code this up properly thank you.[code]<?$login_time=(h,m,s);//get login time hour min sec.$logout_time=(h,m,s);//get logout time hour min sec.$remaningtime=('$login_time<>$logout_time');//calc the diffrence.echo $remaningtime;//echo the remaning time?>[/code] Link to comment https://forums.phpfreaks.com/topic/5275-calc-from-logtime-and-logout-time/ Share on other sites More sharing options...
redarrow Posted March 19, 2006 Author Share Posted March 19, 2006 [!--sizeo:5--][span style=\"font-size:18pt;line-height:100%\"][!--/sizeo--]please goto ken code below to help thank you.[!--sizec--][/span][!--/sizec--]This code gives the effect i wont but i need to get the two times from the database then get the resultthe time was posted in the database as this format time(h,m,s)so what i need is to get that info out of the database in the below code format but how thank you.[code]<?// Pass epoch timestampsfunction calcDateDiff ($date1 = 0, $date2 = 0) { // $date1 needs to be greater than $date2. // Otherwise you'll get negative results. if ($date2 > $date1) return FALSE; $seconds = $date1 - $date2; // Calculate each piece using simple subtraction $weeks = floor($seconds / 604800); $seconds -= $weeks * 604800; $days = floor($seconds / 86400); $seconds -= $days * 86400; $hours = floor($seconds / 3600); $seconds -= $hours * 3600; $minutes = floor($seconds / 60); $seconds -= $minutes * 60; // Return an associative array of results return array( "weeks" => $weeks, "days" => $days, "hours" => $hours, "minutes" => $minutes, "seconds" => $seconds);}// Example: current timestamp with 22:00 12th, January 2003 or use variable(s)if ($diff = calcDateDiff(time(), mktime(22, 00, 00, 1, 12, 2003))) { //Format output any way you like printf("Difference between the two dates is: %d week(s), %d day(s), %d hour(s), %d minute(s), %d second(s).", $diff['weeks'], $diff['days'], $diff['hours'], $diff['minutes'], $diff['seconds']); }?>[/code] Link to comment https://forums.phpfreaks.com/topic/5275-calc-from-logtime-and-logout-time/#findComment-18743 Share on other sites More sharing options...
redarrow Posted March 19, 2006 Author Share Posted March 19, 2006 please help unusall errow what do i do.my error[code]Warning: date(): Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in C:\Program Files\Apache Group\Apache2\htdocs\collage\time.php on line 55Start: Warning: date(): Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in C:\Program Files\Apache Group\Apache2\htdocs\collage\time.php on line 56End: There are 0 days, 0 hours and 0 minutes left[/code]The code i am currently using[code]<?//change user and password to your mySQL name and passwordmysql_connect("xxxx","xxxx","xxxx"); //select which database you want to editmysql_select_db("jojo"); //If cmd has not been initializedif(!isset($tmp)) { //display all the news$tmp=mysql_query("SELECT * FROM log");while ($row = mysql_fetch_assoc($tmp)) { //grab the title and the ID of the news$logout_time=$row["logout_time"];//take out the id $minute = 60; $hour = 60 * 60; $day = $hour * 24; $logout_time = strtotime('logout_time'); $login_time = strtotime('login_time'); $seconds_left = $logout_time - $login_time; $days_left = floor($seconds_left / $day); $hours_left = floor(($seconds_left % $day)/$hour); $minutes_left = floor((($seconds_left % $day) % $hour) / $minute); echo 'Start: ' . date('m/d/Y G:i',$login_time) . "<br />\n"; echo 'End: ' . date('m/d/Y G:i',$logout_time) . "<br />\n"; echo 'There are ' . $days_left . ' days, ' . $hours_left . ' hours and ' . $minutes_left . ' minutes left';}}?>[/code] Link to comment https://forums.phpfreaks.com/topic/5275-calc-from-logtime-and-logout-time/#findComment-18745 Share on other sites More sharing options...
redarrow Posted March 19, 2006 Author Share Posted March 19, 2006 [!--quoteo(post=356349:date=Mar 19 2006, 06:34 AM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Mar 19 2006, 06:34 AM) [snapback]356349[/snapback][/div][div class=\'quotemain\'][!--quotec--]please help unusall errow what do i do.my error[code]Warning: date(): Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in C:\Program Files\Apache Group\Apache2\htdocs\collage\time.php on line 55Start: Warning: date(): Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in C:\Program Files\Apache Group\Apache2\htdocs\collage\time.php on line 56End: There are 0 days, 0 hours and 0 minutes left[/code]The code i am currently using[code]<?//change user and password to your mySQL name and passwordmysql_connect("xxxx","xxxx","xxxx"); //select which database you want to editmysql_select_db("jojo"); //If cmd has not been initializedif(!isset($tmp)) { //display all the news$tmp=mysql_query("SELECT * FROM log");while ($row = mysql_fetch_assoc($tmp)) { //grab the title and the ID of the news$logout_time=$row["logout_time"];//take out the id $minute = 60; $hour = 60 * 60; $day = $hour * 24; $logout_time = strtotime('logout_time'); $login_time = strtotime('login_time'); $seconds_left = $logout_time - $login_time; $days_left = floor($seconds_left / $day); $hours_left = floor(($seconds_left % $day)/$hour); $minutes_left = floor((($seconds_left % $day) % $hour) / $minute); echo 'Start: ' . date('m/d/Y G:i',$login_time) . "<br />\n"; echo 'End: ' . date('m/d/Y G:i',$logout_time) . "<br />\n"; echo 'There are ' . $days_left . ' days, ' . $hours_left . ' hours and ' . $minutes_left . ' minutes left';}}?>[/code][/quote]Going relly mad never work this out 4 hours later still error please help. eyes red lol advance thank you Link to comment https://forums.phpfreaks.com/topic/5275-calc-from-logtime-and-logout-time/#findComment-18769 Share on other sites More sharing options...
redarrow Posted March 20, 2006 Author Share Posted March 20, 2006 [!--quoteo(post=356374:date=Mar 19 2006, 09:24 AM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ Mar 19 2006, 09:24 AM) [snapback]356374[/snapback][/div][div class=\'quotemain\'][!--quotec--]Going relly mad never work this out 4 hours later still error please help. eyes red lol advance thank you[/quote]can somone please help thank you. Link to comment https://forums.phpfreaks.com/topic/5275-calc-from-logtime-and-logout-time/#findComment-18997 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.