Date Library - Suggestions? |
[eluser]Lone[/eluser]
After seeing this previous post today and also having to work out a function this afternoon to calculate number of weeks between two dates I have been inspired to build a Date Library to achieve these somewhat common functions a bit easier. As far as I can tell there isn't any library out there like this The library will essentially be quite a few different helpers but I prefer to build this as a library so they are all a bit more relational. I want to build this as a light-weight library that you can just auto-load and use whenever required without needing to load the library. I think the demand is out there so please make suggestions in here on common functions you think need to be achieved with this Date Library and I will update the list below everyones suggestions. Feel free to post code on how to achieve as well ![]() * It will be presumed that the date helper will also be pre-loaded so feel free to use functions from it in code examples List of suggested functions - Get previous month (allow for setting num of months to go back) - Get yesterday date (allow for setting num of days to go back) - Get num of days between two dates - Get num of months between two dates - Get num of years between two dates
[eluser]xwero[/eluser]
The beginning ![]() Code: class Date {
[eluser]Lone[/eluser]
An awesome start there - thanks for that xwero. Ill start to work through it all shortly and start to form some guidelines for this class. My first thoughts also are what should we do about the what the default inputs for dates actually are. Eg. should it be in a timestamp format, 10/02/2007 format etc. What is the most common (and best) way to store these values? We use timestamps alot but an obvious quick problem is for say when a birthday is before 1970 - there's no such thing! Reminds me of this cartoon.
[eluser]xwero[/eluser]
That is indeed a thing to consider. I once did a class like that and i based the methods on database date methods. I guess we could do a post 1970 date class for the people who want speed and a universal date class for the people who want broader time range (in my class you could go from 1000 01 01 to 9999 12 31) For the format strtotime can process most of the date formats. maybe there needs to be a unix timestamp flag so the dates don't get processed when they don't need to be.
[eluser]kevinprince[/eluser]
MYSQL to HUMAN be this UK or US Ive got them written below Code: /**
[eluser]Lone[/eluser]
Thanks for that contribution nextgengames, keep anymore coming along. xwero: I don't quite follow what you mean - do you mean to have two classes, one for timestamps and the other for another date format? Come to think of it, it wouldn't be too hard to have a private function that can check if date string given is timestamp or not as if it doesn't contain a '/' or '-' then must be a timestamp as far as I can tell. Then it can convert the timestamp to a common format that we would use across the class. My only issue is what is the best format to use other then timestamp. As far as I can tell the mySQL way of yyyy-mm-dd is the best as I have seen it as the most generic way because you can actually order the date values and they will be in date order.
[eluser]timj[/eluser]
Suggested: Get specific day of week (every Weds, for example)
[eluser]Référencement Google[/eluser]
suggestions: - function to calculate an Age from a date of birth - Functions to format MySQL date and datetime (retrieving and formating to human format and inserting from human formats)
[eluser]wiredesignz[/eluser]
suggestion: - a function to calculate the last date of the current month in the current year.
[eluser]ManOfTheHour[/eluser]
It's been a while.... but did you manage to put a date library together? Mind sharing? Thanks!!! |
Welcome Guest, Not a member yet? Register Sign In |