PHP Classes
elePHPant
Icontem

nmDate: Date arithmetic operations and format conversion

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2004-06-15 (11 years ago) RSS 2.0 feedStarStarStar 57%Total: 986 All time: 3,481 This week: 1,419Up
Version License Categories  
nmdate 1.0GNU Lesser Genera...Time and Date
Description Author  

This class is meant to convert dates between Julian and Gregorian formats as well perform several type of date and time calculations.

It can add and subtract a period of time to any date and also calculate the difference of time between two dates.

Picture of Neil Morgan
Name: Neil Morgan <contact>
Classes: 1 package by
Country: United Kingdom United Kingdom
Age: 49
All time rank: 221098 in United Kingdom United Kingdom
Week rank: 1531 Up63 in United Kingdom United Kingdom Up

Details provided by the author  
Date calculation and manipulation
Copyright (c) 2004, Neil Morgan
email n.a.morgan@brighton.ac.uk

This class was created using algorithms for Julian and Gregorian
date manipulation found on the Internet.  A search of Google using 
"Julian Date" or "Julian Date Algorithm" would provide further
information.

Requirements: PHP4 or better (not tested on PHP3).

Features:
Date Conversion to and from Julian representation.
Date Conversion to and from Gregorian representation.
Date and Time calculations.
Interval between given dates.

Limitations:
Must specify long year i.e. 1999 or 2004 instead of '99 or '04
Accepts dates in the UK format i.e. dd/mm/yyyy only.
Does not support dates created in the US format i.e. mm/dd/yyyy.
Date field separators must be either '/', '.' or '-'.

Usage:
There are six methods of constructing the nmDate object.
$var = new nmDate();
	Creates an object with date/time of now.

$var = new nmDate('dd/mm/yyyy');
	Creates an object with specified date at midnight.

$var = new nmDate('TS', Timestamp);
	Creates an object with specified Timestamp.

$var = new nmDate('dd/mm/yyyy','HH:MM:SS');
	Creates an object with specified date and time.

$var = new nmDate(dd,mm,yyyy);
	Creates an object with specified days, months and years.

$var = new nmDate(dd,mm,yyyy,HH,MM,SS);
	Creates an object with specified days, months, years, 
	hours, minutes and seconds.

Methods:
$var->ToJul([ ['AD'] | ['BC'] ]);
	Converts the constructor date to Julian format.  Defaults to 'AD'.

$var->ToGreg()
	Converts Julian date to Gregorian format.

$var->AddDays(NumberOfDays);
$var->AddMonths(NumberOfMonths);
$var->AddYears(NumberOfYears);
$var->SubDays(NumberOfDays);
$var->SubMonths(NumberOfMonths);
$var->SubYears(NumberOfYears);
	Date calculations (addition and subtraction)

$var->GetDay();
	Returns the day of the week i.e. Monday, Tuesday, etc.

$var->GetDateDMY([ [ true ] | [ false ] , [ <Separator> ] ] );
$var->GetDateMDY([ [ true ] | [ false ] , [ <Separator> ] ] );
	Returns date in UK or US format.
	Parameter 1 specifies month in digit or named form i.e. 04 or April.
		False for digit (default), True for named.
	<Separator> specifies date field separator, defaults to '/'.

$var->SetTime([ [ HH ] , [ MM ] , [ SS ] ]);
	Sets the time.  Default is Midnight i.e. 0 hours, 0 minutes and 0 seconds.

$var->GetTime( [ <Separator> ] ); 
	Returns the time separated by <Separator> (defaults to ':').

$var->AddMinutes(NumberOfMinutes);
$var->AddHours(NumberOfHours);
$var->SubMinutes(NumberOfMinutes);
$var->SubHours(NumberOfHours);
	Time calculations (addition and subtraction).
	Date safe.

$var->GetDiff('dd/mm/yyyy','HH:MM:SS');
	Calculates the difference in seconds between the current object's date
	and the given date/time.


  Files folder image Files  
File Role Description
Plain text file date.inc.php Class Date Manipulation Class
Accessible without login Plain text file example.php Example Date Class Examples
Accessible without login Plain text file readme.txt Doc. Documentation for nmDate

 Version Control Unique User Downloads Download Rankings  
 0%Total:986All time:3,481
 This week:0This week:1,419Up
 User Ratings  
 
 All time
Utility:66%StarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:75%StarStarStarStar
Examples:83%StarStarStarStarStar
Tests:-
Videos:-
Overall:57%StarStarStar
Rank:1139