script that calculates the current age up to the last day.. grammar correct.
By : voldomazta
<?
function curage($gm,$gd,$gy){
/**
* Current Age Script
* Coded by Ramon Alivio Jr. (2005-06-12)
* Iloilo City, Philippines
* http://www.thermokarst.co.nr
*
* Usage: -- echo curage(m,d,y); --
* Where 'm' is birth month, 'd' is birth day
* and 'y' is birth year
**/
$r = '';
/**
* days of each month
**/
for($x=1 ; $x<=12 ; $x++){
$dim[$x] = date('t',mktime(0,0,0,$x,1,date('Y')));
}
/**
* vars for current date
**/
$cm = date('n');
$cd = date('j');
$cy = date('Y');
/**
* calculate differences
**/
$m = $cm - $gm;
$d = $cd - $gd;
$y = $cy - $gy;
/**
* if the given day is ahead of the current day
**/
if($d < 0) {
$td = $cd + $dim[$cm];
$tm = $cm - 1;
$d = $td - $gd;
$m = $tm - $gm;
if(($tm - $gm) < 0) {
$tm += 12;
$ty = $cy - 1;
$m = $tm - $gm;
$y = $ty - $gy;
}
}
/**
* if the given month is ahead of the current month
**/
if($m < 0) {
$tm = $cm + 12;
$ty = $cy - 1;
$m = $tm - $gm;
$y = $ty - $gy;
}
/**
* the processing area
**/
if($y < 0) {
die("That date is in the future.");
} else {
switch($y) {
case 0 : $r .= ''; break;
case 1 : $r .= $y.($m == 0 && $d == 0 ? ' year old' : ' year'); break;
default : $r .= $y.($m == 0 && $d == 0 ? ' years old' : ' years');
}
switch($m) {
case 0: $r .= ''; break;
case 1: $r .= ($y == 0 && $d == 0 ? $m.' month old' : ($y == 0 && $d != 0 ? $m.' month' : ($y != 0 && $d == 0 ? ' and '.$m.' month old' : ', '.$m.' month'))); break;
default: $r .= ($y == 0 && $d == 0 ? $m.' months old' : ($y == 0 && $d != 0 ? $m.' months' : ($y != 0 && $d == 0 ? ' and '.$m.' months old' : ', '.$m.' months'))); break;
}
switch($d) {
case 0: $r .= ($m == 0 && $y == 0 ? 'Today' : ''); break;
case 1: $r .= ($m == 0 && $y == 0 ? $d.' day old' : ($y != 0 || $m != 0 ? ' and '.$d.' day old' : '')); break;
default: $r .= ($m == 0 && $y == 0 ? $d.' days old' : ($y != 0 || $m != 0 ? ' and '.$d.' days old' : ''));
}
}
return $r;
}
?>
| 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 Date Time Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Using JSEclipse, JavaScript programmers now have their own Eclipse plug-in that provides many important features to aid in the development of JavaScript applications. JSEclipse gives JavaScript developers the same ease of use that Eclipse has been providing in the Java language and others for years. Learn to use this tool, while creating a colony of evolving "creatures" on your page. FREE! Go There Now!
|
|
|
|
In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset. FREE! Go There Now!
|
|
|
|
This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product. FREE! Go There Now!
|
|
|
|
XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats. 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!
|
|
|
|
Join this webcast to discover the key requirements for successful change and release management. Learn how to extend your .NET environment to improve productivity and collaboration, and address core problems afflicting team development. In this webcast, we’ll review typical challenges faced by customers and how to resolve them with the IBM Rational Change and Release Management solution, including Rational ClearCase, Rational ClearQuest and Rational Build Forge. Replay is available for 9 months. FREE! Go There Now!
|
|
|
|
Regression testing -- in which code is thoroughly tested to ensure that changes have not produced unexpected results -- is an important part of any development process. But many testing environments neglect the terminal-based applications that still form the backbone of many industries. In this tutorial, you'll learn how the Rational Functional Tester Extension for Terminal-Based Applications works with other Rational Functional Tester to help test terminal-based applications quickly and easily. FREE! Go There Now!
|
|
|
|
Investigate the effects of field-level caching in dynamic array access, in part 5 of the UniVerse performance series. FREE! Go There Now!
|
|
|
|
It's a good time to be a Web developer. You've never had more choices in terms of technologies. There are so many great open source Web servers, databases, programming languages, and development frameworks. No matter what combination of technologies you prefer to work with, there is an integrated development environment (IDE) that can increase your productivity: Eclipse. In this tutorial, Part 1 of a three-part "Web development with Eclipse Europa" series on how to use Eclipse for Web development with Java technology, PHP, and Ruby, we'll see how the latest release of Eclipse -- Europa -- can be used to rapidly develop Java Web applications. We'll use Java Platform, Enterprise Edition 5 (Java EE) for Eclipse to build a Web application for tracking and calculating baseball statistics. FREE! Go There Now!
|
|
|
|
Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |