SQL组日期为星期日期

时间:2014-06-07 18:54:54

标签: sql date

我有一个包含func_id和日期格式的表格,如(07.06.14)。我正在尝试创建一个函数,它返回日期的日期数(07.06.14),func_id将等于我要写的func_id。例如:

我的桌子:          func_id 11 / date = 07.06.14

这将从0返回1.(星期六代码= 0);

我试过了:

 function Get_weekday($data){
$dat = explode(".",$data);
$date = date("l", mktime(0, 0, 0, $dat[0]  , $dat[1], $dat[2]));
if($date == "Monday"){return 4;}
if($date == "Tuesday"){return 3;}
if($date == "Wednesday"){return 2;}
if($date == "Thursday"){return 1;}
if($date == "Friday"){return 0;}
if($date == "Saturday"){return 0;}
if($date == "Sunday"){return 0;}
}
function count_per_date($func_id,$day){
$result = mysql_query("SELECT COUNT(date) as data,date FROM entregas WHERE func_id = '$func_id' GROUP BY date");
while($row = mysql_fetch_assoc($result)) 
{
 //That part I dont really know what to do
}}

对不起我的英语,我不会说得很好):

1 个答案:

答案 0 :(得分:0)

您正在寻找DAYOFWEEK

实施例

SELECT DAYOFWEEK('2007-02-03');

更多信息:DAYOFWEEK documentation