robert.access Posted December 30, 2009 Share Posted December 30, 2009 hi I have the following script: <? session_start(); $thedates = $db->get_sql_field("SELECT end_time FROM " . DB_PREFIX . "auctions WHERE auction_id='" . $_REQUEST['id'] . "'", 'end_time'); $thedates = date("Y-m-d H:i:s",$thedates); $countdown_to = "$thedates"; // "YYYY-MM-DD HH:MM:SS" --- time is in 24 hour format $float = 'clear'; // clear - left - right $font = "Arial, 'Times New Romans'"; $font_color = "#000"; $font_size = '8pt'; $font_weight = 'bold'; $width = '250px'; $height = '10px'; $border_width = '1px'; $border_color = '#ccc'; $background = ''; $border_style = 'none'; $padding = '0'; $margin = '0'; $thetimex = date("F d, Y H:i:s", time() + (TIME_OFFSET * 3600)); $count_from = "$thetimex"; function datediff($interval, $datefrom, $dateto, $using_timestamps = false) { /* $interval can be: yyyy - Number of full years q - Number of full quarters m - Number of full months y - Difference between day numbers (eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".) d - Number of full days w - Number of full weekdays ww - Number of full weeks h - Number of full hours n - Number of full minutes s - Number of full seconds (default) */ if (!$using_timestamps) { $datefrom = strtotime($datefrom, 0); $dateto = strtotime($dateto, 0); } $difference = $dateto - $datefrom; // Difference in seconds switch($interval) { case 'yyyy': // Number of full years $years_difference = floor($difference / 31536000); if (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom), date("j", $datefrom), date("Y", $datefrom)+$years_difference) > $dateto) { $years_difference--; } if (mktime(date("H", $dateto), date("i", $dateto), date("s", $dateto), date("n", $dateto), date("j", $dateto), date("Y", $dateto)-($years_difference+1)) > $datefrom) { $years_difference++; } $datediff = $years_difference; break; case "q": // Number of full quarters $quarters_difference = floor($difference / 8035200); while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($quarters_difference*3), date("j", $dateto), date("Y", $datefrom)) < $dateto) { $months_difference++; } $quarters_difference--; $datediff = $quarters_difference; break; case "m": // Number of full months $months_difference = floor($difference / 2678400); while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($months_difference), date("j", $dateto), date("Y", $datefrom)) < $dateto) { $months_difference++; } $months_difference--; $datediff = $months_difference; break; case 'y': // Difference between day numbers $datediff = date("z", $dateto) - date("z", $datefrom); break; case "d": // Number of full days $datediff = floor($difference / 86400); break; case "w": // Number of full weekdays $days_difference = floor($difference / 86400); $weeks_difference = floor($days_difference / 7); // Complete weeks $first_day = date("w", $datefrom); $days_remainder = floor($days_difference % 7); $odd_days = $first_day + $days_remainder; // Do we have a Saturday or Sunday in the remainder? if ($odd_days > 7) { // Sunday $days_remainder--; } if ($odd_days > 6) { // Saturday $days_remainder--; } $datediff = ($weeks_difference * 5) + $days_remainder; break; case "ww": // Number of full weeks $datediff = floor($difference / 604800); break; case "h": // Number of full hours $datediff = floor($difference / 3600); break; case "n": // Number of full minutes $datediff = floor($difference / 60); break; default: // Number of full seconds (default) $datediff = $difference; break; } return $datediff; } $diff = datediff("s", $count_from, $countdown_to); header('Content-Type: text/javascript'); ?> countdown = <?=$diff?>; function convert_to_time(secs) { secs = parseInt(secs); hh = secs / 3600; hh = parseInt(hh); mmt = secs - (hh * 3600); mm = mmt / 60; mm = parseInt(mm); ss = mmt - (mm * 60); if (hh > 23) { dd = hh / 24; dd = parseInt(dd); hh = hh - (dd * 24); } else { dd = 0; } if (ss < 10) { ss = "0"+ss; } if (mm < 10) { mm = "0"+mm; } if (hh < 10) { hh = "0"+hh; } if (dd == 0) { return (hh+" Hours, "+mm+" Minutes, "+ss+" Seconds"); } else { if (dd > 1) { return (dd+" Days, "+hh+" Hours, "+mm+" Minutes, "+ss+" Seconds"); } else { return (dd+" Day, "+hh+" Hours, "+mm+" Minutes, "+ss+" Seconds"); } } } function do_cd() { if (countdown <= 0) { document.write("<div id=\"cd\" style=\"float:<?=$float?>\; margin:<?=$margin?>\; padding:<?=$padding?>\; border: <?=$border_size?> <?=$border_style?> \<?=$border_color?>\; background:\<?=$background?>\; height:<?=height?>\; width:<?=$width?>\; font-family: <?=$font?>\; color: \<?=$font_color?>\;font-size:<?=$font_size?>\; font-weight:<?=$font_weight;?>\; text-align:center\;\">CLOSED</div>\n"); } else { document.getElementById('cd').innerHTML = convert_to_time(countdown); setTimeout('do_cd()', 1000); } countdown = countdown - 1; } document.write("<div id=\"cd\" style=\"float:<?=$float?>\; margin:<?=$margin?>\; padding:<?=$padding?>\; border: <?=$border_size?> <?=$border_style?> \<?=$border_color?>\; background:\<?=$background?>\; height:<?=height?>\; width:<?=$width?>\; font-family: <?=$font?>\; color: \<?=$font_color?>\;font-size:<?=$font_size?>\; font-weight:<?=$font_weight;?>\; text-align:left\;\"></div>\n"); do_cd(); <? exit(); ?> Everithing works fine but My server date it's set with +5 hours (time difference), because I use a server that is 5 hours difference from the site, and I need to set +5 hours in the above script. How can I do that??? Please help. Thank you! Link to comment https://forums.phpfreaks.com/topic/186691-count-down-script-modification/ Share on other sites More sharing options...
oni-kun Posted December 30, 2009 Share Posted December 30, 2009 This code: $thetimex = date("F d, Y H:i:s", time() + (TIME_OFFSET * 3600)); Where is 'TIME_OFFSET' defined? If it isn't, then you can switch it to '5' (5*3600 = +5hrs) Link to comment https://forums.phpfreaks.com/topic/186691-count-down-script-modification/#findComment-985948 Share on other sites More sharing options...
robert.access Posted December 30, 2009 Author Share Posted December 30, 2009 thank you very much for the answer! I will try'it and let you know if working. "Where is 'TIME_OFFSET' defined?" - don't know???? With this script I have a countdown on page and if it finish will display CLOSED.... I will try now your code. thx again Link to comment https://forums.phpfreaks.com/topic/186691-count-down-script-modification/#findComment-985950 Share on other sites More sharing options...
robert.access Posted December 30, 2009 Author Share Posted December 30, 2009 it's not working how exacly to modify? $thetimex = date("F d, Y H:i:s", time() + (TIME_OFFSET * 3600)); Link to comment https://forums.phpfreaks.com/topic/186691-count-down-script-modification/#findComment-985956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.