Jump to content
  • 0
Sign in to follow this  
FinTheHuman

Get next Date(weekday)

Question

Hello,

I am creating a follow-up functionality in my Application and what I want is to get the next day of the date when the form is sent/saved but when the output/result of the date is in the weekend, I want the result of the next day field to be set in the up-coming Monday instead. 

Thanks for the help :D 

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Hi @FinTheHuman,

You can add new Virtual field and use "Calculated value" in the form element then paste this formula to get the next day excluding the weekend:

CASE 

WHEN ((DatePart(dw, GetUTCDate())) = 6)
THEN (DateAdd(day, 3, GetUTCDate()))

WHEN ((DatePart(dw, GetUTCDate())) = 7)
THEN (DateAdd(day, 2, GetUTCDate()))

ELSE (DateAdd(day, 1, GetUTCDate()))

END

I hope this helps :)

~WatashiwaJin~

Share this post


Link to post
Share on other sites
  • 0

Hi @FinTheHuman,

If you want the result to be editable then you will need a custom script to do that, follow this process for the step:

(1) Use a Virtual field to do the calculations of the formula provided earlier and insert a DATETIME field(to store the output of the formula)

(2) then make the Virtual field hidden :

image.png.e2abe891e5b57617354388f7b7899c95.png

(3) Insert a Header & Footer -> and paste this code in the Footer part:

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {

  var src = document.querySelector('[name*=cbParamVirtual1]');
  var dest = document.querySelector('[name*=InsertRecordDATE]');

  src.onchange = function() {
  dest.value = this.value.substring(0,9);
  }
  });
</script>

Important Note:

- Make sure that you unchecked the "Enable HTML editor" in the advance option of the Footer.

- Use the correct name value of your actual field in the script.

- The "var src" is the SOURCE of the value(where the formula is located).

- The "var dest" is the DESTINATION of the formula output (the editable Date field itself).

- This process is working on my end. Feel free to test it out here: https://c1abv183.caspio.com/dp/482760009312d3d82a8949d4987e

 

I hope this helps :) 

~WatashiwaJin~

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...