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

  • SEARCH
  • Home
  • 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 7593301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:08:06+00:00 2026-05-30T21:08:06+00:00

can any post the how to filter a grid view timestamp(Y-m-d h:m:s) column using

  • 0

can any post the how to filter a grid view timestamp(Y-m-d h:m:s) column using date picker.
my model is below

   public function search()
{
    $criteria=new CDbCriteria();

                $criteria->condition="time_up BETWEEN UNIX_TIMESTAMP('$this->time_up_from') AND UNIX_TIMESTAMP('$this->time_up_to')";
    $criteria->compare('proc_id',$this->proc_id);
    $criteria->compare('book_id',$this->book_id);
    $criteria->compare('Project_name', $this->Project_name);
    $criteria->compare('isbn_no', $this->isbn_no);
    $criteria->compare('book_title',$this->book_title);
    $criteria->compare('totalpage',$this->totalpage,true);
    $criteria->compare('totaltime',$this->totaltime,true);
    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
        'pagination'=>array(
        'pageSize'=>100
    ),
    ));
    }

for the normal particular condition its working by below condition

        $criteria->condition = "  time_up LIKE  '$this->time_up%'";

for date range its not working i tried also
wiki/142/ in yii website but no use.
kindly help in this.or give some other methods to darange search for timestamp.

My inputs from advanced search form

        <div class=" wide form">

   <?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
         )); ?>
    <div class="row">
    <?php echo "Time UP from"; ?>
 <?php $this->widget('zii.widgets.jui.CJuiDatePicker',
 array(
  'model'=>$model, 
'name'=>'Process[time_up_from]',
       // Model attribute filed which hold user input
      'options'=>array(
    'showAnim'=>'fold',
    'dateFormat'=>'yy-mm-dd',),
    'htmlOptions'=>array(
    'style'=>'height:20px;width:100px',
    'size'=>15,
    //'value'=>date('Y-m-d'),
    /*'onchange'=>"$.fn.yiiGridView.update('books-grid', {data: $(this).serialize()});" */),));?>
   </div>
    <?php echo "Time Up to"; ?>
   <?php $this->widget('zii.widgets.jui.CJuiDatePicker',
    array(
  'model'=>$model, 
    'name'=>'Process[time_up_to]',
       // Model attribute filed which hold user input
      'options'=>array(
    'showAnim'=>'fold',
    'dateFormat'=>'yy-mm-dd',),
    'htmlOptions'=>array(
    'style'=>'height:20px;width:100px',
    'size'=>15,
    //'value'=>date('Y-m-d'),
    /*'onchange'=>"$.fn.yiiGridView.update('books-grid', {data:      $(this).serialize()});"*/  ),));?>
           </div>
         <?php   echo CHtml::submitButton('Search'); ?>

ANSWER FOR THE PROBLEM

hi i found the answer its just a if condition before criteria condition

`if(strlen($this->time_up_from) && strlen($this->time_up_to))
    {
 $criteria->condition="time_up BETWEEN UNIX_TIMESTAMP('$this->time_up_from') AND UNIX_TIMESTAMP('$this->time_up_to')";
   }

now its working fine.
@bool.dev thank you very much for your suggestions.thanks alot.

  • 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-05-30T21:08:07+00:00Added an answer on May 30, 2026 at 9:08 pm

    Try this:

    public function search(){
    
       $criteria=new CDbCriteria();
    
       if(!empty($this->time_up_from) && !empty($this->time_up_to)){
          $criteria->condition="time_up BETWEEN UNIX_TIMESTAMP('$this->time_up_from') AND UNIX_TIMESTAMP('$this->time_up_to')";
       }
       $criteria->compare('proc_id',$this->proc_id);
       $criteria->compare('book_id',$this->book_id);
       $criteria->compare('Project_name', $this->Project_name);
       $criteria->compare('isbn_no', $this->isbn_no);
       $criteria->compare('book_title',$this->book_title);
       $criteria->compare('totalpage',$this->totalpage,true);
       $criteria->compare('totaltime',$this->totaltime,true);
       return new CActiveDataProvider($this, array(
          'criteria'=>$criteria,
          'pagination'=>array(
             'pageSize'=>100
          ),
       ));
    }
    

    Guessing that time_up_to and time_up_from are virtual attributes that you have declared in your model, take care that you have declared them properly, and also added the safe validator for them, like this:

    // in your model
    public $time_up_from;
    public $time_up_to;
    
    // in the rules of the model
    return array(
      // other rules
      // below is the safe rule
      array('proc_id, book_id, Project_name, isbn_no, book_title, totalpage, totaltime, time_up, time_up_from, time_up_to', 'safe', 'on'=>'search'),
    );
    

    Also in your search form modify the date pickers, as i already mentioned in the comments:

     // remove the 'name'=>'Process[time_up_from]' and use the following line
     'attribute'=>'time_up_from'
     // and remove the 'name'=>'Process[time_up_to]' and use the following line
     'attribute'=>'time_up_to'
    

    Edit :

    As Dcoder pointed out in the comments below, we should always bind params, to prevent sql injection, and possibly get improved performance, hence the modified condition could be:

    if(!empty($this->time_up_from) && !empty($this->time_up_to)){
      $criteria->condition="time_up BETWEEN UNIX_TIMESTAMP(:time_up_from) AND UNIX_TIMESTAMP(:time_up_to)";
      $criteria->params[':time_up_from']=$this->time_up_from;
      $criteria->parmas[':time_up_to']=$this->time_up_to;
    }
    

    From the guide

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

Sidebar

Related Questions

So I have a C program. And I don't think I can post any
Can someone post any simple explanation of cache aware algorithms? There are lot of
How can I http post data to any page in the web in Classic
Is there any way instead of a JS hack where I can post from
Can any data exchanged on a local machine using the loopback IP 127.0.0.1 (localhost)
Can any one help me convert the below code to LINQ? Select Catg,Count(*) From
Can anyone please why does this javascript work only in firefox? function filter(obj, what,
Can any one explain why the output of this code is only 'hello' and
Can any one tell me how to convert an legacy application which is vb6
Can any one tell the bit size of boolean in Java?

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.