note 81452 modified in ref.datetime by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 02:17:50 +0000 |
| Subject: | note 81452 modified in ref.datetime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-141947@lists.php.net to get a copy of this message | ||
<?php
####################################
# Provide week number and get start_timestamp and end_timestamp
#####################################
// this week number will come from the timeshare form
$week = 51;
$times = get_start_and_end_date_from_week($week);
$start_time = $times['start_timestamp'];
$end_time = $times['end_timestamp'];
function get_start_and_end_date_from_week ($w)
{
$y = date("Y", time());
$o = 6; // week starts from sunday by default
$days = ($w - 1) * 7 + $o;
$firstdayofyear = getdate(mktime(0,0,0,1,1,$y));
if ($firstdayofyear["wday"] == 0) $firstdayofyear["wday"] += 7;
# in getdate, Sunday is 0 instead of 7
$firstmonday = getdate(mktime(0,0,0,1,1-$firstdayofyear["wday"]+1,$y));
$calcdate = getdate(mktime(0,0,0,$firstmonday["mon"],
$firstmonday["mday"]+$days,$firstmonday["year"]));
$sday = $calcdate["mday"];
$smonth = $calcdate["mon"];
$syear = $calcdate["year"];
$timestamp['start_timestamp'] = mktime(0, 0, 0, $smonth, $sday, $syear);
$timestamp['end_timestamp'] = $timestamp['start_timestamp'] + (60*60*24*7);
return $timestamp;
} # function datefromweek
?>
--was--
####################################
Provide week number and get start_timestamp and end_timestamp
#####################################
// this week number will come from the timeshare form
$week = 51;
$times = get_start_and_end_date_from_week($week);
$start_time = $times['start_timestamp'];
$end_time = $times['end_timestamp'];
function get_start_and_end_date_from_week ($w)
{
$y = date("Y", time());
$o = 6; // week starts from sunday by default
$days = ($w - 1) * 7 + $o;
$firstdayofyear = getdate(mktime(0,0,0,1,1,$y));
if ($firstdayofyear["wday"] == 0) $firstdayofyear["wday"] += 7;
# in getdate, Sunday is 0 instead of 7
$firstmonday = getdate(mktime(0,0,0,1,1-$firstdayofyear["wday"]+1,$y));
$calcdate = getdate(mktime(0,0,0,$firstmonday["mon"],
$firstmonday["mday"]+$days,$firstmonday["year"]));
$sday = $calcdate["mday"];
$smonth = $calcdate["mon"];
$syear = $calcdate["year"];
$timestamp['start_timestamp'] = mktime(0, 0, 0, $smonth, $sday, $syear);
$timestamp['end_timestamp'] = $timestamp['start_timestamp'] + (60*60*24*7);
return $timestamp;
} # function datefromweek
http://php.net/manual/en/ref.datetime.php