tags:

views:

270

answers:

3

Let's say I have a table with two columns, where a user places a booking.

datefrom               dateto
-------------------------------------------
2009-05-23 00:00:00    2009-05-27 00:00:00

How would I use SQL to return how many days the user will be booking for? All I want is to return the number of days.

+2  A: 

select days=datediff(dd,datefrom,dateto) from table

Eric H.
1 second! :)
leppie
Fantastic. Works perfectly!
EnderMB
+2  A: 

In Oracle:

select dateto - datefrom from table;
l0b0
A: 

SQL-92:

SELECT (dateto - datefrom) DAY
  FROM MyTable;
onedaywhen