Counters Code
  Home arrow Counters Code arrow time_left()
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
COUNTERS CODE

time_left()
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2003-03-09

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Build Web services with transport-level security using Rational Application Developer V7, Part 1: Build Web services and Web services clients

    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!


    NEW! Cook up Web sites fast with CakePHP, Part 4: Use CakePHP&apos;s Session and Request Handler components

    CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP.
    FREE! Go There Now!


    NEW! Download IBM Rational Developer for System z

    Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects.
    FREE! Go There Now!


    NEW! Harnessing the power of SQL and Java for high performance data access

    Join this webcast to see how IBM Data Studio Developer and pureQuery can take the pain out of Java data access. uApplications developed using both Java and SQL have become a common requirement. Database connectivity using Java Database Connectivity (JDBC) to create an application is a multi-step tedious process, and tooling that covers both SQL and Java has been unavailable, until now. IBM Data Studio introduces the pureQuery platform: a high-performance, Java data access platform focused on simplifying the tasks of developing, managing, and optimizing database applications and services.
    FREE! Go There Now!


    NEW! Rational Asset Manager eKit

    Learn how to do more with your reusable assets with the free Rational Asset Manager eKit. The eKit includes demos on how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse. Plus you’ll find white papers and a Webcast that discuss the challenges of a Service Oriented Architecture and how Rational Asset Manager can provide quick and effective solutions.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Manual Tester V7.0.1

    Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually.
    FREE! Go There Now!


    NEW! Understanding Web application security challenges

    As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security.
    FREE! Go There Now!


    NEW! Using Rational Business Developer to enhance your developer productivity

    Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components.
    FREE! Go There Now!


    NEW! Webcast: Eclipse: Empowering the universal platform

    The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now.
    FREE! Go There Now!


    NEW! Webcast: Striking the right balance between manual and automated testing

    Join this webcast to learn how IBM Rational's Functional Testing solution enables you to implement automation your way, at your pace, with your existing staff. In this webcast, you’ll learn how you can eliminate redundancy of manual test scripts, reduce errors, and increase test coverage through test automation. After this presentation you will understand how IBM Rational Functional Testing solution can streamline your manual testing and make test automation easily attainable.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    COUNTERS CODE ARTICLES

    - TG Who's Online
    - Text Based Counter that formats output
    - Counter & visitor statistics
    - Server Uptime Statistics
    - Chris Dingman's Hit Tracker Script
    - Graph Maker Function
    - Simple userOnline class
    - Adv. Log file generator
    - Logwriter
    - time_left()
    - Basic Statistics
    - Easy Counter
    - countCodeLines
    - MySQL Counter
    - bandwidthmeter





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT