+1 for extracting this into a function.  However, this function should be static and it's a good candidate for some basic unit tests.  It's also probably useful to put something in the comment explaining why you went this route and not date/mktime since otherwise somebody is going to helpfully come along and refactor it for us :-)