Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
bilionut
Contributor III
Contributor III

Counting Days in Specific Month between Two Dates

Hi to All,

Starting from this post:

Counting Days in Specific Month between Two Dates

I need to use the date format including hour and minute

For example between 01.01.2017 00:00:00 and 01.02.2017 12:00: 00 it should be 1.5 days

In  the following example, room "w" should have been occupied 100%, meaning 31 days, but after running the script below the result is a total of 34,4999 days and 111%

Where is the mistake?

SET ThousandSep=',';

SET DecimalSep='.';

SET MoneyThousandSep=',';

SET MoneyDecimalSep='.';

SET MoneyFormat='#,##0.00 €;-#,##0.00 €';

SET TimeFormat='hh:mm:ss';

SET DateFormat='MM/DD/YYYY';

SET TimestampFormat='MM/DD/YYYY hh:mm:ss[.fff]';

SET MonthNames='Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec';

SET DayNames='Mon;Tue;Wed;Thu;Fri;Sat;Sun';

tabBookings:

LOAD RecNo() as BookID, *

Inline [

    AptID, Start, End

  w,12/30/2016 14:47:54, 1/8/2017 12:00:00

  w,1/8/2017 12:00:01, 1/25/2017 18:00:00

  w,1/25/2017 18:00:00, 1/29/2017 17:59:59

  w,1/29/2017 18:00:00, 1/31/2017 12:00:00

  w,1/31/2017 12:00:02, 2/13/2017 14:13:05

];

tabMonthOccup:

LOAD *,

     Num(DaysBooked/DaysInMonth,'0%') as Occupancy;

LOAD *,

     MonthName(MonthBookStart) as MonthBook,

     MonthBookEnd-MonthBookStart+1 as DaysBooked,

     MonthStart(MonthBookStart,1)-MonthStart(MonthBookStart) as DaysInMonth;

LOAD BookID,

     Date(RangeMax(Start,MonthStart(Start,IterNo()-1))) as MonthBookStart,

     Date(RangeMin(End  ,MonthStart(Start,IterNo())-1)) as MonthBookEnd

Resident tabBookings

While MonthStart(Start,IterNo()-1)<=End;

x.png

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

tabMonthOccup:

LOAD *,

     Num(DaysBooked/DaysInMonth,'0.0%') as Occupancy;

LOAD *,

     MonthName(MonthBookStart) as MonthBook,

     ((Interval(MonthBookEnd-MonthBookStart)*24)/24) as DaysBooked,

     MonthStart(MonthBookStart,1)-MonthStart(MonthBookStart) as DaysInMonth;

LOAD BookID,

     RangeMax(Start,MonthStart(Start,IterNo()-1)) as MonthBookStart,

     RangeMin(End  ,MonthEnd(Start,IterNo()-1)) as MonthBookEnd

Resident tabBookings

While MonthStart(Start,IterNo()-1)<=End;

View solution in original post

3 Replies
MK_QSL
MVP
MVP

tabMonthOccup:

LOAD *,

     Num(DaysBooked/DaysInMonth,'0.0%') as Occupancy;

LOAD *,

     MonthName(MonthBookStart) as MonthBook,

     ((Interval(MonthBookEnd-MonthBookStart)*24)/24) as DaysBooked,

     MonthStart(MonthBookStart,1)-MonthStart(MonthBookStart) as DaysInMonth;

LOAD BookID,

     RangeMax(Start,MonthStart(Start,IterNo()-1)) as MonthBookStart,

     RangeMin(End  ,MonthEnd(Start,IterNo()-1)) as MonthBookEnd

Resident tabBookings

While MonthStart(Start,IterNo()-1)<=End;

bilionut
Contributor III
Contributor III
Author

Hi Manish,

Thank you for your fast reply. It should work great, but a weird thing is happening.

In the example posted by me, your script works fine, but using real-world data it shows one negative value for DaysBooked

I can not figure out where that can be


 

BookIDOccupancyDaysBookedStartEnd
68100.61199228418.35976851856/11/2016 15:21:567/23/2016 14:47:54
68100.729567652322.61659722226/11/2016 15:21:567/23/2016 14:47:54
68110.23817428327.38340277787/23/2016 14:47:541/8/2017 12:37:49
68110.24278263147.52626157417/23/2016 14:47:541/8/2017 12:37:49
68110.9666666667297/23/2016 14:47:541/8/2017 12:37:49
68110.9677419355307/23/2016 14:47:541/8/2017 12:37:49
68120.551583781417.09909722221/8/2017 12:37:491/25/2017 15:00:31
68130.12987529874.02613425931/25/2017 15:00:311/29/2017 15:38:09
68140.0435002241.34850694441/29/2017 15:38:091/31/2017 12:00:02
6815-0.016129779-0.50002314811/31/2017 12:00:023/13/2017 14:13:05
68150.406207063912.59241898151/31/2017 12:00:023/13/2017 14:13:05
68150.9642857143271/31/2017 12:00:023/13/2017 14:13:05
68160.561534871617.40758101853/13/2017 14:13:055/27/2017 15:09:51
68160.859091621926.63184027783/13/2017 14:13:055/27/2017 15:09:51
68160.9666666667293/13/2017 14:13:055/27/2017 15:09:51
MK_QSL
MVP
MVP

Provide sample data for two different BookID. One showing correct result and one showing negative. I will check and come back to you on this.