I am using created date of ubercart order to compare with filter selected values of date.

created date is in timestamp with time. Where as filter selected values it is just date and if try to convert the date to timestamp, its not fetching accurate results as per filtered dates.

I have attached the image for clear understanding.

enter image description here

enter image description here

I have used this as query:

$query = $query->condition('uc.created',array($from_timestamp,$to_timestamp),'BETWEEN');

Any suggestions ? Thanks in advance.


Instead of using different select boxes for month, date and year, you could use date_popup type.

$form['start'] = array(
    '#title' => t('Arrive'),
    '#type' => 'date_popup',
    '#default_value' => 'YYYY-MM-DD 00:00:00',
    '#date_year_range' => '0:+3',
    '#size' => 12,
    '#required' => true,

Which comes with time field, so you will have the timestamp. Thats it, now you can compare the timestamp input to the database value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.