||01-18-2008 02:17 AM
Need more ideas for date and time class
I'm writing a new date and time class. It'll bring all of PHP's inconsistencies when it comes to date and time together. I've written the main chunk of it, and as you can see from the examples below, I've done quite a lot. You'll also see that I've taken the method chaining approach.
However, is there anything else anybody would like to see in a date and time class? Hopefully I can make this awesome enough to help people out with date and time - it's clearly one of those areas where there are a lot of functions all over the place, different formats of dates, et cetera.
/* Get day in EST */echo $pDateTime
;/* Check if day is a weekend */echo $pDateTime
;/* Check if date is valid */echo $pDateTime
->date('30th February 2008')
;/* Custom format output */echo $pDateTime
->toDate('jS M Y')
;/* Output MySQL date in BST */echo $pDateTime
;/* Days until Christmas 2009 */echo $pDateTime
;/* Difference in hours between GMT and EST */$iTargetDate
|Alan @ CIT
||01-18-2008 11:25 AM
One of the things I've always wanted to see in a date class is a method to compare two dates and return an array of date parts showing the difference.
Also your date() method looks like it can take multiple date formats so it would be handy if you write an add() / sub() method to add or remove to a date.
$newDate = $pDateTime->date('1st February 2008')->add('month', 3);
$newDate = $pDateTime->date('2008-05-26')->sub('day', 20);
If I think of any more I'll let you know.
||01-18-2008 02:22 PM
Thanks for the suggestion, bud :-) All added!
/* Add 3 months to current date and time */echo $pDateTime
->toDate('jS M Y')
|All times are GMT. The time now is 11:01 PM.
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0