Just a little date extension. |
[eluser]Zack Kitzmiller[/eluser]
seriously, nothing fancy. just helpful. Allows for you to figure out relative dates. I use this helper all the time, so I thought you guys and gals may want to use it.. I know it could be a lot better, and check time preferences and what not, but nothing I do is that critical. Lemme know what you think. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
[eluser]xwero[/eluser]
why not use the strtotime function then you don't need to load a helper Code: $yesterday = strtotime('-1 day'); I think the function parameter is close enough to human readable text for even beginners to know what the function does.
[eluser]Zack Kitzmiller[/eluser]
[quote author="xwero" date="1245724714"]why not use the strtotime function then you don't need to load a helper Code: $yesterday = strtotime('-1 day'); I think the function parameter is close enough to human readable text for even beginners to know what the function does.[/quote] Well, I guess because I didn't read the documentation on the strtotime page on php.net, I wrote that helper along time ago when I was just starting php, so never really saw a reason to look further. Thank's for the advice
[eluser]xwero[/eluser]
With the wealth of functions in php you should always check the documentation to see if you are not re-inventing the wheel. For quick checking you can read the function overview page, for example datetime function overview page
[eluser]Iverson[/eluser]
Thanks. Should be helpful to somebody. Even the way you're doing it. One thing though, you have if function_exists('two_weeks_previous') for the last_week() function. You're also checking the last_month() function for the last_year() function. Or maybe I'm missing your logic behind it. Either way, good contribution.
[eluser]sophistry[/eluser]
hi, thanks for putting your stuff out there! it's good to give back to the world. even if cantankerous carpers like me tear it apart. xwero's advice to trend toward concision is well taken. use strtotime() FWIW, do not use this code for anything date critical; this code is riddled with problems that will arise on these dates: new year's eve, new year's day, leap years, februaries, daylight savings switchover days, etc... dealing with dates is maddening and you have to pay attention to details, get experience, and most of all, test, test, test. also, why is every "time" parameter of mktime set to midnight? that is going to cause problems. |
Welcome Guest, Not a member yet? Register Sign In |