Date problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thios
Forum Newbie
Posts: 3
Joined: Mon Jun 16, 2008 5:26 pm

Date problem

Post by thios »

I downloaded a simple countdown PHP script which takes the server time to display the actual date. Could somebody help me on how to modify

$actualDateDisplay = date($dateFormat,$actualDate);

to make it show the time one hour later?
Or do I have to modify this line?:
<?php echo $actualDateDisplay; ?>


The problem is that I am totally new to PHP
Thanks a lot!
thios
Forum Newbie
Posts: 3
Joined: Mon Jun 16, 2008 5:26 pm

Re: Date problem

Post by thios »

Maybe it is better to paste the whole code of this free PHP script, so you know better what to change:

Code: Select all

 
<?php
//*****************************************************************************
//
// MICRO COUNTDOWN  -  Version: 1.0
//
// You may use this code or any modified version of it on your website.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind, either
// expressed or implied, including, but not limited to, the implied warranties
// of merchantability and fitness for a particular purpose. You expressly
// acknowledge and agree that use of this code is at your own risk.
//
//*****************************************************************************
?>
 
 
<?php
// Define your target date here
    $targetYear  = 2008;
    $targetMonth = 07;
    $targetDay   = 20;
    $targetHour  = 15;
    $targetMinute= 00;
    $targetSecond= 00;
// End target date definition
 
// Define date format
$dateFormat = "d-m-Y H:i:s";
 
$targetDate = mktime($targetHour,$targetMinute,$targetSecond,$targetMonth,$targetDay,$targetYear);
$actualDate = time();
 
$secondsDiff = $targetDate - $actualDate;
 
$remainingDay     = floor($secondsDiff/60/60/24);
$remainingHour    = floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
$remainingMinutes = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
$remainingSeconds = floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));
 
$targetDateDisplay = date($dateFormat,$targetDate);
$actualDateDisplay = date($dateFormat,$actualDate);
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MICRO COUNTDOWN</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
  var days = <?php echo $remainingDay; ?>  
  var hours = <?php echo $remainingHour; ?>  
  var minutes = <?php echo $remainingMinutes; ?>  
  var seconds = <?php echo $remainingSeconds; ?>  
 
function setCountDown ()
{
  seconds--;
  if (seconds < 0){
      minutes--;
      seconds = 59
  }
  if (minutes < 0){
      hours--;
      minutes = 59
  }
  if (hours < 0){
      days--;
      hours = 23
  }
  document.getElementById("remain").innerHTML = days+" days, "+hours+" hours, "+minutes+" minutes, "+seconds+" seconds";
  setTimeout ( "setCountDown()", 1000 );
}
 
</script>
</head>
 
<body onload="setCountDown();">
<div id="container">
    <div id="header"><div id="header_left"></div>
    <div id="header_main">Countdown script</div><div id="header_right"></div></div>
    <div id="content">
        <table class="countTable">
           <tr>
             <td>Target date:</td><td><?php echo $targetDateDisplay; ?></td></tr>
           <tr><th colspan="2" id="remain"><?php echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes, $remainingSeconds seconds";?></th></tr>
           <tr>
             <td>Actual date:</td><td><?php echo $actualDateDisplay; ?></td></tr>
       </table>
    </div>
    <div id="footer"><a href="http://www.phpf1.com" target="_blank">Powered by PHP F1</a></div>
</div>
</body>
</html>
 
If you post code here in the future, please enclose it in BBcode tags, as I have done above for you.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Date problem

Post by JAB Creations »

I had a date problem once too though after several attempts I discovered they wouldn't run if I showed up wearing pants.

...oh wait this is a coding thread? Maybe it belongs in a coding forum. :wink:
Post Reply