Working with Dates
Posted: Sat Nov 06, 2010 2:06 pm
I'm working on some invoicing software where I need to store an array of dates(the customer's bill cycle). Customers are generally billed quarterly, but reports are sent out every month. When displaying the report, I need to do some conditional formatting depending on if this invoice reflects a bill cycle month or not.
I'm currently storing the dates in an imploded array of date stamps created using mktime(0,0,0,$month,1,date('Y')) - I was planning on just comparing the date stamps to whatever the date stamp for the invoice was. Then, it occurred to me that any time the year changes those date stamps will be obsolete. Should I just store their bill cycle months as month names and compare the strings with in_array()?
I just wrote the above code as an example, so there may be syntax errors.
Is there a better way to do this? Seems kludgy. Thanks in advance for your input!
I'm currently storing the dates in an imploded array of date stamps created using mktime(0,0,0,$month,1,date('Y')) - I was planning on just comparing the date stamps to whatever the date stamp for the invoice was. Then, it occurred to me that any time the year changes those date stamps will be obsolete. Should I just store their bill cycle months as month names and compare the strings with in_array()?
Code: Select all
$billcycle = array('January','April','July','October');
$invoicedate = mktime(0,0,0,1,1,date('Y')); // Invoice Date: January 1 of this year
$comparedate = date('F',$invoicedate); // Get just the month(January) from $invoicedate
if(in_array($comparedate,$billcycle)) {
// perform conditional formatting
} else {
// don't
}
Is there a better way to do this? Seems kludgy. Thanks in advance for your input!