0

Hi is it possible to count days between columns, something like

datediff(date_finished-date_started) as 'days'

only datediff works just with actual dates, and I'd like to have the days number for every row counted automatically with the rsults in a new temporary column'days'; I hope it makes sense.
Please could you help or point me in right direction. Thank you

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by katties
0

It looks like you've got it right except for the minus sign, (it should be a comma)...

DATEDIFF('date_finished', 'date_started') AS numberDays;

Hi is it possible to count days between columns, something like

datediff(date_finished-date_started) as 'days'

only datediff works just with actual dates, and I'd like to have the days number for every row counted automatically with the rsults in a new temporary column'days'; I hope it makes sense.
Please could you help or point me in right direction. Thank you

0

Thank you, it works, only now it returns values less 1 day, i.e. id start_date and finish_date are the same it returns '0'. Is it possible to change it?

0

I would say you could either put a DATE_ADD() around the dateFinished column....
DATEDIFF(DATE_ADD('date_finished', INTERVAL 1 DAY), 'date_started') AS numberDays;

a DATE_SUB() around the dateStarted column....
DATEDIFF('date_finished', DATE_SUB('date_started', INTERVAL -1 DAY)) AS numberDays;

or just add 1 to the result of your days like so...
DATEDIFF('date_finished', 'date_started') + 1 AS numberDays;

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.