yii2 da ohirgi 7 kunlik malumotlarni chiqarish

+1 ovoz
170 marta ko‘rilgan
so‘radi 23 iyul alfraganus (513 bal)
tahrirlandi 30 iyul Saidolim

Assalomu Aleykum,

Yii2 songi 7 kun ichida kiritilgan malumotlarni chiqarishim kerek, quyidagi yolni sinab kordim lekin natija chiqmadi, xatolik beryapdi, shuni qaysi yo'l bilan xal qilsa bo'ladi?

$query = new yii\db\Query;
$query -> select('name')
       -> from('veloarenda')
       -> Where('DATE(pickupd) 
       -> DATE_SUB(curdate(), INTERVAL 7 DAY')
       -> all();
        
$command = $query->createCommand();
$rows = $command->queryAll();
izoh qoldirdi 23 iyul Sardor Dushamov (1,527 bal)
qanaqa oshibka ?
izoh qoldirdi 23 iyul alfraganus (513 bal)
shu oshibkani bergandi Sardor aka:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
The SQL being executed was: SELECT `name` FROM `veloarenda` WHERE DATE(pickupd) > DATE_SUB(curdate(), INTERVAL 1 DAY

3 Javoblar

+2 ovoz
javob berdi 23 iyul Sardor Dushamov (1,527 bal)
tanlangan 23 iyul alfraganus
 
Eng yaxshi javob
Shuni ko'ringchi 
select * from name where pickupd
    BETWEEN DATE( DATE_SUB( NOW() , INTERVAL 7 DAY ) )
    AND DATE ( NOW() )
izoh qoldirdi 23 iyul alfraganus (513 bal)
Sardor aka, buni yii2 sql query siga tushura olmayapman, yordam berib yubora olasizmi aka iltimos,
men shunaqa qilib ko'rgandim:

Veloarenda::find()->where('pickupd
    BETWEEN DATE( DATE_SUB( NOW() , INTERVAL 7 DAY ) )
    AND DATE ( NOW()')->all();
izoh qoldirdi 23 iyul Sardor Dushamov (1,527 bal)
shu yozganiz ishlamadimi?

$firstdate = date('Y-m-d', strtotime('-7 days'));
$now = date('Y-m-d');
Veloarenda::find()
->where('pickupd
    BETWEEN DATE( :start ) AND  DATE(:end) ')
->addParams([':start' => $firstdate, ':end'=>$now])
->all();

shuni ko'ringchi
izoh qoldirdi 23 iyul alfraganus (513 bal)
ishladi Sardor aka, zo'r ishladi, katta rahmat aka :-)
0 ovoz
javob berdi 23 iyul MrHope (411 bal)
tahrirlandi 30 iyul Saidolim
$month = Students::find()
   -> where('concat( year(now()), mid(pickupd,5,6) )
            BETWEEN now() AND date_add(now(), interval 7 day)')
   -> all();
izoh qoldirdi 23 iyul alfraganus (513 bal)
aka, bu yo'l bilan chiqmadi
0 ovoz
javob berdi 30 iyul Specialist001 (143 bal)
tahrirlandi 30 iyul Saidolim
$query = new yii\db\Query;
$query -> select('name')
            -> from('veloarenda')
            -> where('DATE(pickupd))
            -> DATE_SUB(curdate(), INTERVAL 7 DAY')
            -> all();
        
$command = $query->createCommand();
$rows = $command->queryAll();

manimcha siz pickupd degandan keyin qavsni tashab ketgansiz. shuni qo'yib ko'ringchi

izoh qoldirdi 30 iyul Specialist001 (143 bal)
o'zi gap sintaksis xatoligida bo'lyapti. 2-3 marotaba " va ( ) larni yana bir tekshirib chiqing

Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.

Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin.

Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Telegram kanal YordamUzRss

...