php - Calculate dates relative to input date -
with code have now, managed return dates way off in 1969 , 1970.example of $enddate 23-8-2013. day, month, year.
$enddte = date_create_from_format('j-n-y', $enddate); echo date('y-m-d', strtotime('-1 sunday', strtotime($enddte))). date('y-m-d', strtotime('+1 saturday', strtotime($enddte)));
this code doesn't seem give me previous sunday , next saturday relative date given i'm wondering if i'm doing wrong.
date_create_from_format
returns datetime
object, not string should run through strtotime
...:
$date = date_create_from_format('j-n-y', $enddate); $startdate = clone $date; $startdate->modify('-1 sunday'); $enddate = clone $date; $enddate->modify('+1 saturday'); echo $startdate->format('y-m-d').' => '.$enddate->format('y-m-d');
Comments
Post a Comment