Monday, January 4, 2010

Generate Week Date Using Date & Strtotime Function

I published on 2010-01-05 date.
So Output we be as follow :

$current_day = date("N"); //numeric representation of the day of the week : 2 for(Tuesday)

$days_to_friday = 5 - $current_day; // print 3 output
$days_from_monday = $current_day - 1; //print 1 output
$monday = date("Y-m-d", strtotime("- {$days_from_monday} Days"));
$friday = date("Y-m-d", strtotime("+ {$days_to_friday} Days"));


$timestampoffrom = strtotime($monday);
$timestampofto = strtotime($friday);

No comments:

Post a Comment