PHP - 日期跨越格式

Is there a function or class out there that cleanly formats timespans with php?

Given 2 date-stamps: it would check if the both dates have the same year. If so remove one. Same month? remove one.

Example:
23 March 2002 – 13 January 2009  –>  23 March 2002 – 13 January 2009
23 March 2002 – 13 April 2002  –>  23 March – 13 April 2002
03 March 2002 – 15 March 2002  –>  03 – 15 March 2002

Maybe I should just do this with some if-else statements? It just looks messy but It might be the only way...

Just asking for some advice. Thanks!

Have a look at the built-in Date classes. They're really good. In this specific case, I think you're looking for DateTime::diff, which creates a DateInterval object.