简体   繁体   English

如何比较上周和上个月的日期函数

[英]how to compare last week and last month date functions

$start = strtotime('this week');
$results =$wpdb->get_results("SELECT count( doctor_name ) AS totalleads FROM  `wp-leads-count` WHERE doctor_name ='Sasanthi' and leads_date >='". $start."'");

this is my code to get last week leads count from table doctor name and where date with in this week (means today is thusday then start from previous week) it not working?? 这是我从表医生姓名获取上周潜在客户计数的代码,以及本周的日期(今天是今天,然后从上周开始)在哪里?

and have do same for function like last month ?? 并做同样的功能,如上个月?

in my db i use this leads_date field as timestamp 在我的数据库中,我将此leads_date字段用作时间戳

you can use the date_sub function from mysql 您可以从mysql使用date_sub函数

get all records from last week 获取上周的所有记录

SELECT count(doctor_name) AS totalleads FROM `wp-leads-count` WHERE doctor_name ='Sasanthi' and leads_date between date_sub(now(),INTERVAL 1 WEEK) and now()

get all records from last month 获取上个月的所有记录

SELECT count(doctor_name) AS totalleads FROM `wp-leads-count` WHERE doctor_name ='Sasanthi' and leads_date between date_sub(now(),INTERVAL 1 MONTH) and now()

try 尝试

$daynumber = date('N', date('d'));// getting today day number
$prevweek = $daynumber+7; // starting from prev week 
echo $prevdate = strtotime('-'.$prevweek.' days'); // prev week date
echo strtotime("-1 month"); // last month

For more :- Getting last month's date in php 有关更多信息:- 在PHP中获取上个月的日期

day of the week to day number (Monday = 1, Tuesday = 2) 星期几至星期几(星期一= 1,星期二= 2)

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

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