ตอนนี้มัน Error
Warning: odbc_exec(): SQL error: [Microsoft][SQL Server Native Client 11.0][SQL Server]The conversion of a varchar data type to a datetime data type resulted in an out-of-range value., SQL state 22008 in SQLExecDirect in D:\Apache24\htdocs\Bootstrap\ThaiStatistics\detail_opd.php on line 41
Code (PHP)
<?php
$nowYear = date('Y');
$startYear = 2549-543;
for($year=$nowYear;$year>=$startYear;$year--)
{
echo "<tr>";
echo "<td>".($year+543)."</td>";
for($month=1;$month<=12;$month++)
{
for($day=1;$day<=31;$day++)
{
$strSQL= "SELECT COUNT (VN) as total FROM DN_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '".$nowYear."-".$month."-".$day."' AND '".$nowYear."-".$month."-".$day."' AND Cxl='0'";
$objExec = odbc_exec($conn,$strSQL) or die ("Error Execute [".$strSQL."]");
while($objResult = odbc_fetch_object($objExec))
{
echo "<td>$objResult->total</td>";
}
//$day++;
//echo $day."<br>";
}
}
$nowYear--;
echo "<tr>";
}
?>
<?php
$number = cal_days_in_month(CAL_GREGORIAN, 8, 2003); // 31
echo "There were {$number} days in August 2003";
?>
[/php
Code (PHP)
[php]<?php
/*
* days_in_month($month, $year)
* Returns the number of days in a given month and year, taking into account leap years.
*
* $month: numeric month (integers 1-12)
* $year: numeric year (any integer)
*
* Prec: $month is an integer between 1 and 12, inclusive, and $year is an integer.
* Post: none
*/
// corrected by ben at sparkyb dot net
function days_in_month($month, $year)
{
// calculate number of days in a month
return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
}
?>
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-1' AND '2018-1-1' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-2' AND '2018-1-2' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-3' AND '2018-1-3' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-4' AND '2018-1-4' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-5' AND '2018-1-5' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-6' AND '2018-1-6' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-7' AND '2018-1-7' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-8' AND '2018-1-8' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-9' AND '2018-1-9' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-10' AND '2018-1-10' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-11' AND '2018-1-11' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-12' AND '2018-1-12' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-13' AND '2018-1-13' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-14' AND '2018-1-14' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-15' AND '2018-1-15' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-16' AND '2018-1-16' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-17' AND '2018-1-17' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-18' AND '2018-1-18' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-19' AND '2018-1-19' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-20' AND '2018-1-20' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-21' AND '2018-1-21' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-22' AND '2018-1-22' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-23' AND '2018-1-23' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-24' AND '2018-1-24' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-25' AND '2018-1-25' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-26' AND '2018-1-26' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-27' AND '2018-1-27' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-28' AND '2018-1-28' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-29' AND '2018-1-29' AND Cxl='0'
SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '2018-1-30' AND '2018-1-30' AND Cxl='0'
Code (PHP)
<?php
function days_in_month($month, $year)
{
// calculate number of days in a month
return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
}
$nowYear = date('Y');
$startYear = 2549-543;
for($year=$nowYear;$year>=$startYear;$year--)
{
echo "<tr>";
echo "<td><b>".($year+543)."</b></td>";
for($month=1;$month<=12;$month++)
{
$dmonth =days_in_month(CAL_GREGORIAN, $month, $year);
echo "There were" .$dmonth. "days in month ".$month."-".$year."<br>";
for($day=1;$day<=$dmonth;$day++)
{
$strSQL= "SELECT COUNT (VN) as total FROM DNHOSPITAL_TEST.dbo.HNOPD_MASTER WHERE VisitDate BETWEEN '".$nowYear."-".$month."-".$day."' AND '".$nowYear."-".$month."-".$day."' AND Cxl='0'";
$objExec = odbc_exec($conn,$strSQL) or die ("Error Execute [".$strSQL."]");
//echo $strSQL."<br>";
while($objResult = odbc_fetch_object($objExec))
{
//echo "<td> $objResult->total<br> </td>";
}
$day++;
}
$month++;
}
$nowYear--;
echo "</tr>";
}
?>
อยากได้ Query แบบนี้คะ Code (PHP)
SELECT COUNT (VN) FROM [DNHOSPITAL_TEST].[dbo].[HNOPD_MASTER] WHERE [VisitDate] BETWEEN '2018-03-01' AND '2018-03-31';