views:

263

answers:

5

Hi,

I am looking for library (open source) like Joda Time in Java world. is there any library like that ?

Joda Time is very helpful to calculate date and time. I can add days, weeks, month, year and also can converting date and time easily.

I wish there is library like joda time for PHP

edit: I need some functions that available in Joda Time like daysBetween (to calculate number of days between 2 date), monthsBetween and weeksBetween ... Some functions about add and substract date is available from php itself.

A: 

Hi,

i know an component of the Zend Framework : Zend_Date. It works fine for this Job.

Iam not sure, but you can use it without the whole Framework.

Zend Date

ArneRie
A: 

I'm not familiar with Joda, but did you took a look into DateTime? It does all the things (and some more) that you've mentioned.

Alix Axel
A: 

strtotime and date can sometimes do wonders, especially if you are working with dates >= 1970 (ie, which can be coded as a UNIX timestamp).

If you are using a recent enough version of PHP, the DateTime class (added in PHP 5.2 ; but several methods were added in PHP 5.3) might be helpful too -- other Date and Time classes could help, too.

Pascal MARTIN
thanks, i just knew about strtotime. :) strtotime is nice but there are no functions like, daysBetween, weeksBetween, monthsBetween. joda have all i need to plays with date.
nightingale2k1
+1  A: 

There is no need for external library. PHP is more than capable of this already.

<?php
/** These examples work with the current time **/
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";

/** This is a made up time **/
$lessMonth = strtotime("06/19/1986 3:00PM")
$lessMonth = strtotime("-1 month", $lessMonth);

echo $lessMonth, "\n";
echo gmdate('c', $lessMonth);

/** 86 400 seconds in a day */
$daysBetween = (strtotime("now") - $lessMonth) / 86400
?>
Cody N
A: 

You can try this library for PHP Date and time http://nuclearscripts.com/php/scripts-and-programs/date-and-time/php-date-library.html

Quoting from there

The PHP Date Library is collection of professional native PHP functions to work with dates. It does not require any PHP extensions. This library includes most useful functions to work with dates. It includes functions to validate the date, shift date by given amount of days, calculate difference between two dates, calculate week number for given date and much more. It properly handles leap years and is ISO compatible. Professional programmer has spent 3+ days to study the subject, code the library, write manual and put it all here.

I havn't tested it personally.

Manish Sinha