0

I'm working on a function to see if an SMS was sent within the last 5 days of 'today'. I can already check if it's been sent today (see below) but I'm struggling with the up to 5 days earlier part.

// Check if SMS already sent today
        if ($this->sms_sent == $today->format('Y-m-d'))
        {
            return true;
        }

I need to know if the SMS was sent up to 5 days ago.

1 Answers1

0

use this

    $now=date('Y-m-d');
    $days_ago = date('Y-m-d', strtotime('-5 days', strtotime($now )));//get five days before date
    if($this->sms_sent <= $now && $this->sms_sent >= $days_ago) {
        // It's between
    }
Saty
  • 22,443
  • 7
  • 33
  • 51
  • And from where does `$now` come from?! – Rizier123 Apr 01 '15 at 09:51
  • 1
    Answer is still poorly formatted and doesn't explain anything what you did and why you did it, So OP and further readers don't know what you did here, which means that they won't learn much from this answer – Rizier123 Apr 01 '15 at 09:57
  • i will try to present my answer in proper formatted and try to explain my code. – Saty Apr 01 '15 at 10:00
  • You need a second or two more? Or do you want to leave it in this quality? – Rizier123 Apr 01 '15 at 12:23