简体   繁体   English

从给定的月份和年份中选择一条记录

[英]Select a record from given month and year

Select a record from given year and month. 从给定的年份和月份中选择一条记录。 I am doing like this 我就是这样

if ($_REQUEST['thismonth']!=''){

         $fromdate = $_REQUEST['thismonth']."-01 00:00:00";

         $todate = $_REQUEST['thismonth']."-31 23:59:59";

        $fdate=explode('-',$fromdate);
        //print_r($fdate);

         $year1=$fdate[0];
        $month1=$fdate[1];
        $date = $year1=$fdate[0]."-".$month1=$fdate[1];

$result=mysql_query("select * from tbl_daily_rpt where date like '%$date%' order by cdate desc");

    }

and date format in tbl_daily_rpt table like this way 2017-02-28 . 在tbl_daily_rpt表和日期格式像这样2017年2月28日 when echo a $date value is given a 2017-02 . 当echo $ date值被赋予2017-02 Select all the records which date like this 2017-02 选择所有日期为2017-02的记录

试试这个查询

SELECT * FROM tbl_daily_rpt where YEAR(`date`) = '2017' AND MONTH(`date`) = '02'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM