Jump to content
Sign in to follow this  
telly

Generate an expiration date

Recommended Posts

I need to find a workaround to generate an expiration date that is 2 years from the 1st day of the month. 

So, if I enter a value on 02/25/2019, Their expiration date to be 02/01/2020.

Kindly help me with this, please?

Share this post


Link to post
Share on other sites

Hi @telly,

You may try this possible workaround.

1.  On your Submission DataPage, go to Configure Fields and add a Header and Footer Element 
2. Go to the Footer and disable the HTML editor by going to the Advanced tab and unchecking the box next to "Enable HTML editor".
3. Click the Standard tab.
4. Add the following code to add 2 years and always set it to the 1st day 
 

sample.thumb.png.a1f4ea4989fef7a81741fc5a1e36ca76.png


JavaScript code:

<script>
//detect event onchange on the textfield of certificate date
document.getElementById('InsertRecordLast_InsertDate').onchange = function(event){

//place value of certificate date into a new Date class and put it in a variable
var InsertDate = new Date(document.getElementById('InsertRecordLast_InsertDate').value);

//get the first day of the same month but 2 years after
var lastDate = new Date(InsertDate.getFullYear() + 2, InsertDate.getMonth(), 1);

//date.getMonth() starts from 0, so add 1 then make sure it displays with 0 when lower than 10
if(lastDate.getMonth() < 9) {
var lastMonth = "0" + (lastDate.getMonth() + 1);
} else {
var lastMonth = (lastDate.getMonth() + 1);
}

//place the value to the expiration date textfield
document.getElementById('InsertRecordExpiration_Date').value = lastMonth + "/1/" + lastDate.getFullYear();
}
</script>

 

 

Share this post


Link to post
Share on other sites

Try to use this syntax in a formula field or Calculated Field:

 

What is does is:

1.) Add 2 Years to the current Date

2.) Get the First Day of the resulting date by: subtracting the current (DAYofMonth-1) to the resulting date.

DATEADD(
  YEAR,
  2, 
  DATEADD(
    DAY,
    1 - DAY([@field:date]),
    [@field:date]
  ) 
)

 

Hope this information helps.

 

Regards,

DN31337

Share this post


Link to post
Share on other sites
On 1/26/2019 at 9:23 PM, DefinitelyNot31337 said:

Try to use this syntax in a formula field or Calculated Field:

 

What is does is:

1.) Add 2 Years to the current Date

2.) Get the First Day of the resulting date by: subtracting the current (DAYofMonth-1) to the resulting date.


DATEADD(
  YEAR,
  2, 
  DATEADD(
    DAY,
    1 - DAY([@field:date]),
    [@field:date]
  ) 
)

 

Hope this information helps.

 

Regards,

DN31337

Hi @telly,

This solution is great, for more details about how to set up a calculated field in your DataPage you may refer to the links below.

https://howto.caspio.com/datapages/datapage-components/calculated-values/
https://howto.caspio.com/faq/reports-datapages/calculated-fields-and-datediff-function/

I hope this helps.

Regards,

TsiBiRu

Share this post


Link to post
Share on other sites

In addition to @DefinitelyNot31337's definitely genius solution, in case you're wondering how to get the last day of the current month, you may to use this syntax:

 

DATEADD(
month, 
1,

DATEADD(
    DAY,
    -DAY('[@cbTimestamp*]'),
    '[@cbTimestamp*]'
  )

)

 

Hope this helps,

TroubleShooter

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
Reply to this topic...

×   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...