Calculate days between dates

  • 27 February 2018
  • 16 replies
  • 16 views

Badge +11

Hello all.

I have created an absence list where users can select the dates which by default the time is set to 00:00

It is OK until you use the information to create a calendar.

example: from 27/02/2017 00:00 until 28/02/2017 00:00 > actually means 2 days

because it is the whole day of 27th as well as the whole day of 28th.

but majority of users would class it as 1 day only.

How to overcome this problem?

The form has got From Date and Until Date for selection.

The calculated value has got the formula copied from this page

https://community.nintex.com/thread/1879

Now, here are the issues;

- some users select only the FROM date example 27/02/2018 00:00 for 1 day

- some users select From 27/02/2018 00:00 Until 27/02/2018 00:00 for 1 day

If the times are not modified then the formula does not know what to do when 00:00 on same day.
Technically if it is 1 day then it would be like this: 27/02/2018 00:00 Until 27/02/2018 23:59

This is so the calendar view can pick up the date & times.

How can I make so the default timing for the UNTIL date is automatically set to 23:55 (that's highest I can select).?

As well as to exclude the weekends days and show only working days.

Examples below:

What is the best approach for this ?!


16 replies

Userlevel 5
Badge +14

what about if you set up a validation rule that would check that date difference is greater than some lowest time period possible to book (eg. 1 hour)?

it would force users to fill in both date controls and change default time values.

Badge +11

just to get the ball rolling... how would I validate the time difference?

if(dateDiffHours(date1, date2)<1)

as per the process: is this an efficient process what I have done so far?
or would you advise something else instead?

Userlevel 3
Badge +12

Hi,

I have implemented similar kind of requirement. 

First thing is, you have to determine whether or not to capture the time portion?

In my scenario, there are 2 kinds of leave types, full day (will not capture the time portion), partial day (will capture the time portion).

For the above requirement, I created below columns in the list.

1. FullDayBeginDate - Date & Time - Date Only

2. FullDayEndDate - Date & Time - Date Only

If user is applying for One day only, he/she must select Begin Date and End Date.

When entering the leave details in the Calendar, pass the "Event Date" and "End Date" and  "All Day Event", that's it... SharePoint's calendar takes care of it.

Let me know if you need any additional details.

Userlevel 5
Badge +14

simply

dateDiffHours(date1, date2)<1

or better (since dateDiff* functions always return absolute value)

dateDiffHours(date1, date2)<1 && (date2 > date1)

reg. whether it's not efficient or, I do not know all your requirements.

but very probably I would let users book absence directly to the calendar. they would there decide on their own whether they book just few hours off or all day absence or even repeated absence.

Badge +11

Hi Marian

cheers for the feedback.

the following only works when both dates are the same (dateDiffMinutes(FromDate, UntilDate) < 30)

however if e.g 28/02/2018 00:00 and 29/02/2018 00:00 then the above formula does not work.

I am confused ...

Badge +11

Hey Krishna,

Thanks for the feedback.

The requirements I had was to make a form where users can request, holidays, time off, training, offsite, holiday AM/PM and so forth and so on. At that time, there was no requirement to view the requests in a calendar view happy.png

Now since the form is up and running, it has been put forward that it may be good to have a calendar view as well.

With that in mind, my initial form did not ask the users to define the hours, although the date & time were present but nobody bothered to select the times.

When creating the calendar view, as you can imagine, all the requests with dates like this:

from 28/02/2018 00:00 until 29/02/2018 00:00

means that the calendar sees it only one day, although it means to be 2 days from 28th 12am until 29th 11:59pm

So, how to rectify this??

Only thing I can think of is to manually update each request :/

In mean time, I am implementing that BOTH dates (FromDate and UntilDate) are mandatory as well as to validate the UntilDate when it is less than 30minutes between prompt user to specify the time as well. see above formula.

In your scenario, you have created the form in a calendar view happy.png 
which is much better but this was not a requirement in my case but came later ...

Userlevel 5
Badge +14

try to calculate with valid date values laugh.png

213657_pastedImage_2.png

Badge +11

I am validating with real values.

the example above was my silly mistake!

from 28/02/2018 00:00 until 1/03/2018 00:00

but the formula does not validate it unless both dates are same.

The validation should check if the UntilDate > TIME is not less than 15min

I am  also trying something like this but is not working:

dateDiffDays(FromDate,UntilDate) > 0 && dateDiffMinutes(FromDate, UntilDate) < 15

which means if FromDate and UntilDate is more than 1 day in difference AND time is less than 15min THEN display error.

Badge +11

Update:

I think this is much complicated as I initially thought.
Because, if I validate the following

dateDiffDays(FromDate,UntilDate) > 0 && dateDiffMinutes(FromDate, UntilDate) < 1440

than all it does it takes the 1440 minutes into account and as soon as you go over 2 or 3 days then the minutes are not valid because the gap is much wider between the dates.

Unless there is a way asking the TIME not to be 00:00 for the UntilDate via JavaScript ?!
Do let me know guys happy.png

Userlevel 5
Badge +14

I'm somehow lost within your explanation, and what problem you exactly experience

could you post how does  dateDiffMinutes(FromDate, UntilDate) evaluate for you and what you see as a problem?

for me the calculation seems to work correctly.

eg.

213658_pastedImage_1.png

213668_pastedImage_2.png

213669_pastedImage_3.png

213671_pastedImage_5.png

213672_pastedImage_6.png

213673_pastedImage_7.png

213674_pastedImage_8.png

only problem might be in case difference result is zero. in that case nintex evaluates it to empty string instead of zero.

I'm not sure why nintex decided to do so, by definition the function should always return numeric value.

Badge +11

Hi,

I think you have not read my post happy.png there is no problem in displaying the dateDiffMinutes .. that works

but the aim is to make the user to specify the TIME within the UntilDate field, instead of 00:00

Userlevel 5
Badge +14

you might try check like

Number(dateDiffMinutes(UntilDate,CurrentDate)) > 0

CurrentDate reference always returns midnight.

note however, it will work with older forms releases but not in recent ones. there is bug with how CurrentDate evaluates in the recent releases.

Badge +11

what function is the Number ?! I do not have it in the Runtime Function list.
as per the formula; it remains in validation state and does not accept any time.

Userlevel 5
Badge +14

add a calculated value control on the form and feed it with following formula.

what does it return?

typeof {Common:CurrentDate}
Badge +11

UPDATE

In mean time I have added the calculated value naming showUntilDate with the following formular 

formatDate(UntilDate,"HH")

which shows only the hour to 0

and then validate the UntilDate field as following:

contains(showUntilDate, "0")

now the validation works as soon as it picks up the 0 from any date range.

Just cannot believe all the time I spend for a "little" thing like this :/
unbelievable, the workaround it needs doing to get a validation working.

Thanks for your support Marian Hatala

Badge +11

BUT there is a catch:

assuming the From date / time is 10:00 until 15:00

with the above formula, it means that the 15:00 will be flagged as red :/

Maybe I need to change "mm" to "HH" instead .

arrghhhh

Reply