开发者

Establishing month length and first day

Is there a simple way of, given a month and a year, establishing:

  • How many days there are in that month (factoring in leap years) Done
  • What day of开发者_开发问答 the week the first day fall upon?


See http://php.net/manual/en/function.cal-days-in-month.php

$num = cal_days_in_month(CAL_GREGORIAN, 8, 2003); // 31

and weekdays:

$weekday = date("l", mktime(0,0,0,$month,$day,$year));
$print ($weekday);

The latter is not very efficient but seems nicer than using getdate:

$my_t=getdate(date("U"));
print("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]");

Output like

Wednesday, September 29, 2011


You may find the answer to your questions with all needed variables and calculations by going to wikipedia. http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week


Take a look at the date function, particularly date('t') for the number of days in the month (ie the month given in time()) and date('t',$epoch) for the number of days of the month represented by the timestamp $epoch (which, of course, is given in epoch).

And for the day of the week, there's date('l',$epoch) (where the first argument is a lower-case 'L').

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜