5 Replies Latest reply: Sep 26, 2014 9:36 AM by Emilien Petrini

# Calculate hours between two dates

Hi all,

I want to know the numbers of hours between two dates.

 date_creation_h date_prise_charge_h 02/01/2014 23:14 06/01/2014 09:37 03/01/2014 16:24 06/01/2014 09:35 09/01/2014 03:32 09/01/2014 09:56 11/01/2014 01:05 13/01/2014 10:11 15/01/2014 07:11 15/01/2014 09:44 16/01/2014 16:42 16/01/2014 18:11

In my script :

Main :

SET TimeFormat='hh:mm';

SET DateFormat='DD/MM/YYYY';

SET TimestampFormat='DD/MM/YYYY hh:mm';

Time(([Date clôture  ] - [Date de prise en charge  ]),'hh:mm') as tps_traitement

This doesn't work, if somebody have an idea!

Thanks.

Emilien

• ###### Re: Calculate hours between two dates

Hi,

Use Interval()

like interval(dateField2-dateField1,'hh:mm')

Regards

• ###### Re: Calculate hours between two dates

Or to return hours only using 'hh' instead of 'hh:mm'

• ###### Re: Calculate hours between two dates

i used this script with your data

SET TimeFormat='hh:mm';

SET DateFormat='DD/MM/YYYY';

SET TimestampFormat='DD/MM/YYYY hh:mm';

Interval( Timestamp(date_creation_h) - Timestamp(date_prise_charge_h)) as Hours,

Timestamp(date_creation_h) as date_creation_h,

Timestamp(date_prise_charge_h) as date_prise_charge_h;

date_creation_h, date_prise_charge_h

02/01/2014 23:14, 06/01/2014 09:37

03/01/2014 16:24, 06/01/2014 09:35

09/01/2014 03:32, 09/01/2014 09:56

11/01/2014 01:05, 13/01/2014 10:11

15/01/2014 07:11, 15/01/2014 09:44

16/01/2014 16:42, 16/01/2014 18:11

];

To get this result. Does it work ?

• ###### Re: Calculate hours between two dates

This syntax work also :

date_creation_h, date_prise_charge_h,

interval(date#(date_prise_charge_h, 'DD/MM/YYYY hh:mm') - date#(date_creation_h, 'DD/MM/YYYY hh:mm'), 'hh') as h1,

date#(date_prise_charge_h, 'DD/MM/YYYY hh:mm') - date#(date_creation_h, 'DD/MM/YYYY hh:mm') as h2

Thank you all

• ###### Re: Calculate hours between two dates

(date_prise_charge_h-date_creation_h)*24