Query Between with QDatetime Field

Login or register to post comments
3 replies [Last post]
Offline
Joined: 12/09/2010

Hello all,

I'm working with a table in Mysql that contains columns of type DateTime. Those are converted into QDateTime fields.

When I try the following query...

return Episodio::QueryArray(
                QQ::Between(
                    QQN::Episodio()->Fecha, $myQDateTimeVar, $myQDateTimeVar2));

... Qcubed throws the following exception:

Unable to cast QDateTime object to string

#0 L:\Desarrollo\series\includes\qcubed\_core\framework\QType.class.php(246): QType::CastObjectTo(Object(QDateTime), 'string')
#1 L:\Desarrollo\series\includes\qcubed\_core\framework\QQuery.class.php(824): QType::Cast(Object(QDateTime), 'string')
#2 L:\Desarrollo\series\includes\qcubed\_core\framework\QQuery.class.php(963): QQConditionBetween->__construct(Object(QQNode), Object(QDateTime), Object(QDateTime))
#3 L:\Desarrollo\series\semana.php(54): QQ::Between(Object(QQNode), Object(QDateTime), Object(QDateTime))
#4 L:\Desarrollo\series\semana.php(22): SemanaForm->CargarEpisodios()
#5 L:\Desarrollo\series\includes\qcubed\_core\base_controls\QFormBase.class.php(289): SemanaForm->Form_Create()
#6 L:\Desarrollo\series\semana.php(91): QFormBase::Run('SemanaForm', 'semana.tpl.php')
#7 {main}

It seems I should use string fields for the comparison, not QDateTime. Is it true? and if so, how should I compare dates?

Thank you all for your help :)

alex94040's picture
Offline
Joined: 11/06/2008

Consider converting the QDateTimes into strings by explicitly converting them with the appropriate format.

For example:

QQ::Between(QQN::Episodio()->Fecha,
$dateTime1->qFormat(QDateTime::FormatIso),
$dateTime2->qFormat(QDateTime::FormatIso))

Offline
Joined: 04/22/2009

Hello Alex,

Is there a particular reason why QQConditionBetween does an explicit string conversion? In QQConditionEqual for instance we call:

<?php
$this
->objQueryNode->GetValue($this->mixOperand, $objBuilder, true)
?>

that does exactly the conversion for QDateTime you are suggesting.

Would that be worth a ticket?

Cheers

Helge

alex94040's picture
Offline
Joined: 11/06/2008

No good reason for QQConditionBetween to be doing this conversion. I think a ticket is very much warranted :-)