Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript从mysql获取当月数据?_Javascript_Node.js_Typescript - Fatal编程技术网

如何使用javascript从mysql获取当月数据?

如何使用javascript从mysql获取当月数据?,javascript,node.js,typescript,Javascript,Node.js,Typescript,我有记录表,只需要获取当月记录 代码: 在上面的代码中,我通过特定的日期来获取记录。但我的要求是,若请求并没有任何日期,那个么我只想获取当前月份的数据。您能帮助我吗?如果startDate和endDate为空,请使用以下命令查找当月的第一个日期和最后一个日期: var date = new Date(); var firstDateOfCurrentMonth = new Date(date.getFullYear(), date.getMonth(), 1); var endDateOfCur

我有记录表,只需要获取当月记录

代码:


在上面的代码中,我通过特定的日期来获取记录。但我的要求是,若请求并没有任何日期,那个么我只想获取当前月份的数据。您能帮助我吗?

如果startDate和endDate为空,请使用以下命令查找当月的第一个日期和最后一个日期:

var date = new Date();
var firstDateOfCurrentMonth = new Date(date.getFullYear(), date.getMonth(), 1);
var endDateOfCurrentMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0);
现在您可以将这些日期指定给startDate和endDate


如果startDate和endDate为空,请使用以下命令查找当月的第一个日期和最后一个日期:

var date = new Date();
var firstDateOfCurrentMonth = new Date(date.getFullYear(), date.getMonth(), 1);
var endDateOfCurrentMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0);
现在您可以将这些日期指定给startDate和endDate

请注意你想要的时区和日期格式,可以是任何一种


请注意您想要的时区和日期格式。它可以是任何

检查startDate和endDate是否为空。如果两者都为空,请查找当月的第一个日期和最后一个日期。在本例中,startDate=firstDateOfCurrentMonth和endDate=endDateofcurrentMonth感谢您的解决方案。还有一件事,在这段在endDate创建的代码中,结果是到2020年8月20日为止,它没有给出第21个日期记录。检查SQL查询并验证endDate的值。检查startDate和endDate是否为空。如果两者都为空,则查找当前月份的第一个日期和最后一个日期。在本例中,startDate=firstDateOfCurrentMonth和endDate=endDateofcurrentMonth感谢您的解决方案。还有一件事,在这段在endDate创建的代码中,结果是直到2020年8月20日,它没有给出第21个日期的记录。检查SQL查询并验证endDate的值是多少。
statDate=firstDateOfCurrentMonth;  
endDate=endDateOfCurrentMonth;
var date = new Date(); 

var firstDay = new Date(date.getFullYear(),date.getMonth(), 1);  
                
var lastDay = new Date(date.getFullYear(),date.getMonth(), daysInMonth(date.getMonth()+1, 
                        date.getFullYear())); 

firstDay=>Tue Sep 01 2020 00:00:00 GMT+0530 (India Standard Time) 
 
lastDay=> Wed Sep 30 2020 00:00:00 GMT+0530 (India Standard Time)