Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i would like calculate
C#
time interval between 2date,hour,minute,second

;
for example i have starttime: 2016-08-26 08:50:05.0 and endtime 2016-08-19 18:01:48.0

i want to get endtime - startime in firebird

What I have tried:

i tried this query :
select datediff(MINUTE,'2010-01-22 15:29:55.090','2010-01-22 15:30:09.153') / 1000.0 as Secs

but i get this error :

Engine Error (code = 335544569):
Dynamic SQL Error.
SQL error code = -104.
Unexpected end of command - line 1, column 89.

SQL Error (code = -104):
Invalid token.
Posted
Updated 1-Sep-16 21:38pm

1 solution

Why don't you follow Firebird's datediff() syntax[^]?

Which would lead you to something like
firebird
SELECT DATEDIFF(MINUTE FROM CAST('2010-01-22 15:29:55.090' AS DATE) TO CAST('2010-01-22 15:30:09.153' AS DATE)) / 1000.0 AS Secs


As a side note, if you divide the number of minutes obtained by 1000, you will not get the number of seconds. If you want to get the number of seconds from the number of minutes, you have to multiply minutes by 60.

Finally, as a general rule, you should always have a look at the reference pages of the database engine you are using (i.e., Firebird). SQL language is not universal across all engines, there are some common words between all but each one also has its tiny specificities. Copy-pasting a SQL code of another engine and expecting it to work is accepting to loose at bunch of time.

Kindly.
 
Share this answer
 
Comments
Sake562 2-Sep-16 3:58am    
I looked firebird's datediff() syntax but i cannot solve problem
phil.o 2-Sep-16 5:37am    
What did you change in your query after having read the reference?
Sake562 2-Sep-16 7:20am    
SELECT DATEDIFF(day FROM START_TIME TO END_TIME) FROM TABLE_NAME
I WROTE THIS CODE AND IT WORK THANK YOU

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900