Lutz Horn | 3 Mar 2008 17:42
Gravatar

Re: Like on DateTime using only date

Hi Gustavo,

Am 03.03.2008 um 17:21 schrieb Gustavo Niemeyer:
>> with at DateTime property I'd like to compare only using the date
>> part. But the like method of DateTime needs a datetime.datetime
>> instance, not a datetime.date instance. How can I formulate the like
>> condition to only select those records whose DateTime propery match a
>> datetime.date instance?
>
> I'm not sure I understand what's the problem you're facing.  The
> DateTime indeed needs a datatime object.  We may extend it to support
> automatic conversion from date objects, but it should be fairly simple
> to make it work as it is now.
>
> Can you provide some sample code that is failing, and that you're  
> having
> trouble to make it work correctly?

I've the following table in MySQL:

mysql> describe screenings;
+----------+--------------+------+-----+---------+----------------+
| Field    | Type         | Null | Key | Default | Extra          |
+----------+--------------+------+-----+---------+----------------+
| id       | int(11)      |      | PRI | NULL    | auto_increment |
| when     | datetime     | YES  |     | NULL    |                |
| movie_id | int(11)      | YES  |     | NULL    |                |
+----------+--------------+------+-----+---------+----------------+

Using Strom, the corresponding model class is:
(Continue reading)

James Henstridge | 4 Mar 2008 03:03
Picon
Gravatar

Re: Like on DateTime using only date

On 04/03/2008, Lutz Horn <lutz.horn@...> wrote:
> Hi Gustavo,
>
>  Am 03.03.2008 um 17:21 schrieb Gustavo Niemeyer:
>
> >> with at DateTime property I'd like to compare only using the date
>  >> part. But the like method of DateTime needs a datetime.datetime
>  >> instance, not a datetime.date instance. How can I formulate the like
>  >> condition to only select those records whose DateTime propery match a
>  >> datetime.date instance?
>  >
>  > I'm not sure I understand what's the problem you're facing.  The
>  > DateTime indeed needs a datatime object.  We may extend it to support
>  > automatic conversion from date objects, but it should be fairly simple
>  > to make it work as it is now.
>  >
>  > Can you provide some sample code that is failing, and that you're
>  > having
>  > trouble to make it work correctly?
>
>
>
> I've the following table in MySQL:
>
>  mysql> describe screenings;
>  +----------+--------------+------+-----+---------+----------------+
>  | Field    | Type         | Null | Key | Default | Extra          |
>  +----------+--------------+------+-----+---------+----------------+
>  | id       | int(11)      |      | PRI | NULL    | auto_increment |
>  | when     | datetime     | YES  |     | NULL    |                |
(Continue reading)

Lutz Horn | 4 Mar 2008 08:38
Gravatar

Re: Like on DateTime using only date

Hi James,

On Tue, 4 Mar 2008 11:03:11 +0900, "James Henstridge"
<james@...> said:
> You could try something like this:
> 
> today = datetime.date.today()
> start = datetime.datetime.combine(today, datetime.time(0,0))
> end = start + datetime.timedelta(days=1)
> 
> results = self.store.find(
>     Screening, Screening.when >= start, Screening.when < end)
> 
> That is, pick all screenings that fall within the desired time interval.

That works like a charm, thank you!

Lutz


Gmane