I want to get the number of days of the week of the current month. for instance
in a day
Sep. 1st, Monday
must return 1
1
Oct. 1st, Wednesday
must return 3
3
21.11.2014
must return 6
6
Try the following:
var_dump(date('N', mktime(0, 0, 0, date('n'), 1)));
It is not clear from your question whether your input is a string or whether the function should accept the current month / year, which is right now.
$weekdayNumber = date('N', strtotime($datestring));
This returns 1:
date('N', strtotime('Sep. 1st, Monday'));
This returns 3:
date('N', strtotime('Oct. 1st, Wednesday'));
date('N', ...), :
date('N', ...)
<?php date_default_timezone_set('UTC'); echo date('N', strtotime('First day of month')) . PHP_EOL; echo date('N', strtotime('Sep. 1st, Monday')) . PHP_EOL; echo date('N', strtotime('Oct. 1st, Wednesday')) . PHP_EOL;
: http://codepad.org/mr6itbjK
, ( "", "" ), :
echo date('N', strtotime('Sep. 1st')); // this assumes "this year" echo date('N', strtotime('Sep. 1st 2014')); echo date('N', strtotime('2014-09-01')); echo date('N', strtotime('Oct. 1st')); // this assumes "this year" echo date('N', strtotime('Oct. 1st 2014')); echo date('N', strtotime('2014-10-01'));
. http://php.net/manual/en/function.strtotime.php