RE: [PHP] need a function that converts week number to start-end dates... (re-post)
| From: | Jason Wong | Date: | Fri, 04 Aug 2000 07:52:19 +0000 |
| Subject: | RE: [PHP] need a function that converts week number to start-end dates... (re-post) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-10088@lists.php.net to get a copy of this message | ||
Daevid
these are actually part of a library of Calendar related functions that I'm
writing:
Usage should be self explanatory.
#///////////////////////////////////////////////////////////
#===========================================================
# array week_Numbers ($year, $start_wday, $fmt)
#-----------------------------------------------------------
# Returns an array containing the [Week number][Date] in the
# format specified by $fmt for the $year using $start_wday
# as the start of week.
#
# $fmt is as per PHP date() format
#
# Arguments
# ---------
#
# $year : the year in the format "YYYY"
# $start_wday : in the format "Monday", "Tuesday" etc.
#
# Returns
# -------
#
# array : [Week number][Date]
#
#===========================================================
function week_Numbers ($year, $start_wday, $fmt) {
$day = 0;
while ($tmp_day != $start_wday) {
$day++;
$tmp_day = mysql_DAYNAME("$year-1-$day");
}
$week_date = mktime(0, 0, 0, 1, $day, $year);
$wn = 1;
while (($wn <= 53) AND (date("Y", $week_date) == $year)) {
$return["$wn"] = date($fmt, $week_date);
$week_date += 604800;
$wn++;
}
return $return;
}
#///////////////////////////////////////////////////////////
#===========================================================
# string mysql_DAYNAME ($date)
#-----------------------------------------------------------
# Returns a string containing the weekday name for the date
# value $date
#
# Arguments
# ---------
#
# $date : the date in the format "YYYY-MM-DD"
#
# Returns
# -------
#
# string : the weekday name eg "Monday"
#
#===========================================================
function mysql_DAYNAME ($date) {
$tmp = explode("-", $date);
$tmp = mktime(0, 0, 0, $tmp[1], $tmp[2], $tmp[0]);
$return = date("l", $tmp);
return $return;
}
regards
-
Jason Wong
Digital View Ltd
2201 Nanyang Plaza
57 Hung To Road
Kwun Tong
HONG KONG
Tel: +852-2861-3615
Fax: +852-2520-2987
www.digitalview.com
> -----Original Message-----
> From: Daevid Vincent [mailto:DayWalker@TheMatrix.com]
> Sent: 03 August 2000 10:22
> To: PHP General
> Subject: [PHP] need a function that converts week number to start-end
> dates... (re-post)
>
>
> Anyone have a function that would convert a week number (1-52) into the
> corresponding start/end dates?
>
> We want to have reports done from data in the database, and currently, we
> have the 'start date' and 'end date' all working just fine etc, but
> we'd
> like it if there were two select boxes, one with "week 1"..."week 52" and
> the other with the year (I assume i need that too right?),
>
> then somehow this function would just convert the week and year into the
> proper 'start/end dates'...
>
> I see this:
> http://www.php.net/manual/function.strftime.php
> (which by the way, is not mentioned in my "Core PHP Programming" book by
> Leon Atkinson??)
>
> but this tells me the opposite of what I need. this gives me the
> Week given
> the date.
>
> daevid.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>