Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8317723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:42:12+00:00 2026-06-08T21:42:12+00:00

We are using Yii Framework and have created a search form to include the

  • 0

We are using Yii Framework and have created a search form to include the following DatePicker widge:

<?php echo $form->labelEx($model, 'availability_start_date');?>
        <?php 
        Yii::import('zii.widgets.jui.CJuiDatePicker');
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'name'=>'stattDate',
            'options'=>array(
                'showAnim'=>'fold',
            ),
            'htmlOptions'=>array(
                'style'=>'height:20px;'
            )
        ));
        ?>

This widget needs to be used to search for users who have an availability_start_date +/- 2 days from the value specified in the above widget.

Our UserController has the following join logic:

if ($search_frm['availability_start_date']){
                    $join .= ' LEFT JOIN user_availability_start_date usd on u.id = usd.id';
                    $where .= 'AND usd.availability_start_date >= '.$search_frm
                ['availability_start_date'];
                }

Currently the logic in the WHERE clause just asks for a match where the availability_start_date is greater than or equal to the widget’s value.

How do I modify the above WHERE clause to select those records where the widget’s value is +/- 2 days different than the availability_start_date value?

UPDATE: I’ve revised the where clause to read as follows:

if ($search_frm['availability_start_date']){
                    $join .= ' LEFT JOIN user_availability_start_date usd on u.id = usd.id';
                    $where .= ' AND usd.availability_start_date >= DATE_ADD('.$search_frm.', 
                INTERVAL -2 DAY)
                    AND usd.availability_start_date <= DATE_ADD(' .$search_frm.', INTERVAL 2 DAY)';
                }

Unfortunately, when I test the logic, records are returned that don’t meet this criteria. No errors are thrown on the form or page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:42:14+00:00Added an answer on June 8, 2026 at 9:42 pm

    DATEDIFF() returns a value in days. For +/- 2 days you will want to use the absolute value ABS() returned by DATEDIFF(), verify that it is <= 2.

    $where .= "AND ABS(DATEDIFF(DATE(usd.availability_start_date), DATE('" . $search_frm['availability_start_date'] . "'))) <= 2";
    

    I have also wrapped the arguments to DATEDIFF() in DATE() to truncate off the time portions if they are present. Remove those if they are unnecessary for your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using PHP Yii Framework with MongoDB(yiimongodbsuite). I have created a Model which
I'm developing a CMS using Yii Framework. In developing the theme I have a
We've been developing a web application (PHP, using the Yii PHP framework) that is
I am using mysql with php Yii framework.When doing data modelling I came accross
I am using YII framework for my web application . I have a question
I want to create simple form using CForm (yii framework) but 'elements' => array('username'=>array('type'=>'text'))
I am using the yii framework and have different user accounts. When I want
To begin, I'm working entirely in PHP using the Yii framework, although Yii ultimately
I have decided to start coding using OOP and a PHP framework. I have
I have started using Yii framework and I have a -newbie- question about the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.