ranged datetime query problem

Sean Wilson snw at paradise.net.nz
Thu Jun 1 16:16:16 CDT 2006


I'm having problems with an SQL query and some datetime fields and I 
have a couple of quick questions.

Here's my SQL query:
SELECT SUM(time_spent) FROM tblTimes
WHERE
(start_time BETWEEN '1/5/2006 0:00:00:000' AND '31/5/2006 0:00:00:000')
AND
(stop_time BETWEEN '1/5/2006 0:00:00:000' AND '31/5/2006 0:00:00:000')
AND
(job_name_ptr->job_name = 'Job Name');

I have a table named tblTimes with 4 fields: start_time (datetime); 
stop_time (datetime); job_name_ptr (objectPtr); time_spent (virtual 
datetime - method: stop_time - start_time)
Being where I am I have my date format set to DDMMYYYY, though I've 
also tried it as MMDDYYYY and have the same problem.
When I run the query above, I have a valid (and correct) SUM() 
returned to me, but as soon as I cross a month boundary in my BETWEEN 
clause - for example (start_time BETWEEN '1/5/2006 0:00:00:000' AND 
'1/6/2006 0:00:00:000') - I get 00/00/0000 00:00:00:000 returned, 
which seems incorrect.

Questions: is this expected behaviour (that is, should my range sum 
"break" when I cross a border at a month) and if so, how can I run a 
query that will give me the info I want?

Thanks,
-Sean.




More information about the Valentina mailing list