Tag Archives: date math

Saving time with PHP and date math

18 Jan

You may have cringed when read­ing the term “date math,” which sounds both cum­ber­some and dif­fi­cult. It brings to mind the addi­tion and sub­trac­tion of tricky num­bers like 7, 29, and 31; and con­cepts like “two weeks from now,” “yes­ter­day,” and “next month.” And if you’ve every tried to build a sys­tem that tracks rel­a­tive dates you know such things can be a hassle.

So why bother? Because date math is very use­ful! For exam­ple, sup­pose you man­age a web­site that includes due dates, sub­mis­sion dead­lines, and pri­or­ity reg­is­tra­tion peri­ods that recur. If you’re me, you man­age a site that’s full of such dates that recur every aca­d­e­mic quar­ter. Keep­ing these dates in sync is a task that PHP’s date math func­tions were born writ­ten to do.

(more…)