
I am a user note maintainer on the php Documentation team. I spend a lot of time everyday reading new notes and comments that have been added to the documentation. It is us maintainers that decide whether a user note stays in the documentation or needs to be removed. We simply just have to ask ourselves: “Does this note or comment truly bring a good amount of benefit to the reader, or is it just taking up space and/or repeating what has previously been said?”.
There are definitely some gems. A lot of passionate people out there come up with some excellent ideas, examples, and suggestions. If that was all there was, we would not be needed to help maintain the user notes. Unfortunately, the majority of the notes fall more into the garbage category.
I wanted to take this opportunity to talk about a certain php function that just does not get used in situations it ought to be used in. I am talking about strtotime(). I can not tell you home many times I have had to delete a note because it consisted of 10+ lines of code that in the end, determined what day was last Monday. With strtotime(), its as easy as writing strtotime(”Last Monday”) - and than bam, you are returned the Unix time stamp of last Monday.
Is strtotime() limited to just this use? - NO! They have packed in so many amazing string variables into this function that its ease of use is amazing. If you have a badly formatted date string that strtotime() does not understand, its easy enough to correct that date string and put it in a readable format with other php functions and still in the end, you have coded so much less than you would have if you were using some of the functions I have seen.
I guess I would understand if this function was a php5 only function, since it seems so many people are out there and not up to date with the latest php. But that is not the case, strtotime has been available since php4! This simple little function can be so useful. I highly suggest that if you code php and deal with a lot of awkward formed date strings, you need to look into this function.
To catch many more articles like this in the future, make it easy on yourself and subscribe to me via RSS. You will not regret it!
Add This Site To Your Technorati Favorites!Let me know that you added me by posting a comment below and then I will add you as a favorite of mine as well!
Please Give Me Some Rice!Giving me "rice" on Nice4Rice.com also benefits you by giving you a free linkback on that site too.


ReformatThis is a Sole Proprietorship Company owned and operated by RJ Matthis. This website is the personal blog of RJ Matthis and will contain a wide range of rambling thoughts. Everything from technical php tips to posts full of RJ's creative nonsense.






PHP is so powerful - it’s really amazing! Are you going to be writing more PHP articles?
I hope to. I’m going to work out the brain muscle and see if I have any talent at technical articles.
Its hard though, a lot of people that come to php want the quick answers - strtotime() is a quick answer, but a lot of functions do take practice of teaming many together to make happen all the wonderful things it is capable of happen.
Very true, a lot of visitors want the quick and easy answer - especially with a specialized topic like PHP but, if you build a reputation for a site that has the answers, they will keep coming back!
Interesting tip– I can follow what you’re saying about people going the unorthodox route.
Very interresting function. I’ll be sure to use it next time I need to convert or get times.
I use strtotime. It’s great! I’m pretty new to php though I do have a programming background. I was reluctant to switch from Perl to php, but I’m glad I did!
[…] Lerdorf To your expanding branches fed by Coder’s hard work Oh why do people refuse to use strtotime()? The correct function for the job makes your app […]