Home

See the related posts

Mysql server version using php function – mysql_get_server_info()    Text file prompt download or force download using php    Number of lines in a file using php    Check Image exists or Not Using php and GD    PHP Warning: Call-time pass-by-reference has been deprecated   

Find First and Last days in Any Week

This script will help you to find first and last days in any week. You need to specify a date and the code will produce the start date of that week and also the end date. Considering the week starts on monday and ends on saturday.

<?php
$today=date('Y-m-d'); //here we are specifying current date, instead give any date in 'Y-m-d' format. eg: 2009-10-15.
list($year,$month ,$day ) = explode('-',$today );
$timestamp=mktime(0, 0, 0, $month, $day, $year);
$firstday=date("Y-m-d", strtotime("last sunday", $timestamp));
$lastday=date("Y-m-d", strtotime("next sunday", $timestamp));
list($year1,$month1,$day1) = explode('-',trim($lastday));
$timestamp1=mktime(0, 0, 0, $month1, $day1, $year1);
$lastdate=date("Y-m-d", strtotime("-1 days", $timestamp1));
echo 'start date of the week is '.$firstday.' and last date of the week is '.$lastdate;
?>

Home

See the related posts

Mysql server version using php function – mysql_get_server_info()    Text file prompt download or force download using php    Number of lines in a file using php    Check Image exists or Not Using php and GD    PHP Warning: Call-time pass-by-reference has been deprecated   

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment