CodeIgniter Forums

Full Version: date / time help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello, i have something this but dont know how make it for month *check/reset every month, (i tried something but i don't know how test it, cannot wait for end of month) can someone help me remake it for months? (reset every month) Angel

Code:
public function getWeekStartEnd()
    {
           $ts = time();
        

        if (date('w', $ts) == 1)
        {
            $start = strtotime('today', $ts);
        }
        else
        {
            $start = strtotime('this week last monday', $ts);
        }
    
        if (date('w', $ts) == 0)
        {
            $end = strtotime('today', $ts);
        }
        else
        {
            $end = strtotime('this week next sunday', $ts);
        }
        
     
        return array(date('Y-m-d H:i', $start), date('Y-m-d H:i', $end + 60*60*23 + 60*59));
    }
Maybe this is helpful:

To find the first day of the current month:
PHP Code:
$d = new DateTime('first day of this month');
echo 
$d->format('Y-m-d'); 

To find the last day of the current month:
PHP Code:
$d = new DateTime('last day of this month'); 
echo 
$d->format('Y-m-d');