Current location: Hot Scripts Forums » Programming Languages » PHP » Day elapsed countdown.


Day elapsed countdown.

Reply
  #1 (permalink)  
Old 11-19-03, 07:01 AM
Jaeboy Jaeboy is offline
New Member
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Day elapsed countdown.

I looked everywhere for a counter that can count the number of days faded away written in php but couldn't find one, so i decided to write my own this is the first time I deal with time and dates please correct me if am wrong.

Code:
<?
//
// James Wong 2003
//

//The day from which to start counting
$x_day2   = 19;     // Day of the countdown 
$x_month2 = 10;      // Month of the countdown 
$x_year2  = 2003;   // Year of the countdown 
$x_hour2  = 23;     // Hour of the day 

//Retrieving current date from server
$x_month = date("m");
$x_day = date("d");
$x_year = date("y");

//Subtracting current date with specified date
$x_result = $x_day - $x_day2; //calculate days
$x_resultm = $x_month - $x_month2; //calculate months

//Just a text that will appear with the results
$x_prefix = "Community has ";

//If day is 0 then community must be new! I suspect a fail here...
if($x_result == 0)
$x_l_day = "This is a brand new site! Up for <b>0</b> days only!";
elseif ($x_result < 2) //Plural and singular, days and day function
$x_l_day = $x_prefix . "<b>" . $x_result . "</b> day old";
elseif ($x_result > 1)
$x_l_day = $x_prefix . "<b>" . $x_result . "</b> days";

if($x_resultm > 1)
$x_l_month = $x_resultm . " and months old";
else
$x_l_month = "";

//the final result
$x_total = $x_l_day . $x_l_month;

//Echo!!
echo $x_total;

//
// END TIMER
//
?>
@PROS: Anything wrong with the script?
Reply With Quote
  #2 (permalink)  
Old 11-19-03, 09:23 AM
YourPHPPro's Avatar
YourPHPPro YourPHPPro is offline
Community VIP
 
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
Test this script with the following:

Code:
//Retrieving current date from server
$x_month = 1;           
$x_day = 10;           
$x_year = 2004;
It should yield something like 52 days old. Instead it yields -9.

Once this takes into account the year, it should be good to go.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 05:52 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.