A countdown script that tell you how many days, hours, mins, secs are left to your target. Target Date & Target Time supported, also 12 hours format or 24 hours format supported also.
By : madcitysw
<?php
/*
@author Shane Morton <shane@shanemorton.net>
@filename time_left.php4
@version 1.0
Time Left - A function to find out how many days, hours, secs, mins that is left until the target
I was very sad with most of the countdown scripts that I had found that was for php because they didn't support time
for the target. So I needed one very bad and I have looked all over and didn't find one that would do what I wanted,
so I created this one that really works. All you have to do is call the
function time_left($target_month, $target_day, $target_year, $target_hour, $target_min, $target_sec, $target_am_pm)
and it will return the time that it is left until the target. It supports both 12 or 24 hours format. To use the
12 hour format, enter AM or PM in the $target_am_pm. When using the 12 hour format, you can only enter 1 - 12
in the field. To use the 24 hour format, leave the $target_am_pm blank. When using the 24 hour format, you can only
enter 0 - 23 in the field.
24 Hours Format
12AM = 0
1AM = 1
2AM = 2
3AM = 3
4AM = 4
5AM = 5
6AM = 6
7AM = 7
8AM = 8
9AM = 9
10AM = 10
11AM = 11
12PM = 12
1PM = 13
2PM = 14
3PM = 15
4PM = 16
5PM = 17
6PM = 18
7PM = 19
8PM = 20
9PM = 21
10PM = 22
11PM = 23
Error Codes
-1 = There's no time left to the target.
-2 = Error: Month Format Incorrect (Must be in the 1 - 12 range)
-3 = Error: Day Format Incorrect (Must be in the 1 - 31 range)
-4 = Error: Year Format Incorrect (Must be at least 4 chars long and it must be in the 1950 - 2050 range)
-5 = Error: Hour Format Incorrect (If using 12 hour format, must be in the 1 - 12 rnage, if using 24 hour format,
must be in the 0 - 23 range)
-6 = Error: Min Format Incorrect (Must be in the 0 - 59 range)
-7 = Error: Sec Format Incorrect (Must be in the 0 - 59 range)
*/
define("_Time_Left_In_Target", -1);
define("_Error_Target_Month_Format", -2);
define("_Error_Target_Day_Format", -3);
define("_Error_Target_Year_Format", -4);
define("_Error_Target_Hour_Format", -5);
define("_Error_Target_Min_Format", -6);
define("_Error_Target_Sec_Format", -7);
function time_left($target_month, $target_day, $target_year, $target_hour, $target_min, $target_sec, $target_am_pm) {
if ($target_month < 1 or $target_month > 12) {
return _Error_Target_Month_Format;
}
if ($target_day < 1 or $target_day > 31) {
return _Error_Target_Day_Format;
}
if ($target_year < 1950 or $target_year > 2050 or strlen($target_year) < 4 or strlen($target_year) > 4) {
return _Error_Target_Year_Format;
}
if ($target_am_pm == "AM" or $target_am_pm == "PM") {// 12 Hours Format
if ($target_hour < 1 or $target > 12) {
return _Error_Target_Hour_Format;
} else {
if ($target_am_pm == "AM" && $target_hour == 12) {
$target_hour = 0;
} elseif ($target_am_pm == "PM" && $target_hour >= 1 && $target_hour <= 11) {
$target_hour = $target_hour + 12;
}
}
} else {// 24 Hours Format
if ($target_hour < 0 or $target_hour > 23) {
return _Error_Target_Hour_Format;
}
}
if ($target_min < 0 or $target_min > 59) {
return _Error_Target_Min_Format;
}
if ($target_sec < 0 or $target_sec > 59) {
return _Error_Target_Sec_Format;
}
$target = mktime($target_hour, $target_min, $target_sec, $target_month, $target_day, $target_year);
$diff = $target - time();
$time_left["days"] = ($diff - ($diff % 86400)) / 86400;
$diff = $diff - ($time_left["days"] * 86400);
$time_left["hours"] = ($diff - ($diff % 3600)) / 3600;
$diff = $diff - ($time_left["hours"] * 3600);
$time_left["mins"] = ($diff - ($diff % 60)) / 60;
$diff = $diff - ($time_left["mins"] * 60);
$time_left["secs"] = ($diff - ($diff % 1)) / 1;
if ($time_left["days"] < 0 or $time_left["hours"] < 0 or $time_left["mins"] < 0 or $time_left["secs"] < 0) {
return _Time_Left_In_Target;
} else {
return $time_left;
}
}
?>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Counters Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications. FREE! Go There Now!
|
|
|
|
As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications. FREE! Go There Now!
|
|
|
|
Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services. FREE! Go There Now!
|
|
|
|
As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
|
|
|
|
Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7. FREE! Go There Now!
|
|
|
|
Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository. FREE! Go There Now!
|
|
|
|
As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms. FREE! Go There Now!
|
|
|
|
Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |