Jump to content

Add X Number Of Days To A Date Field


Recommended Posts

I am trying to add a variable number of days to a date field.  Here is my script:

 

 var v_NewDate = new Date();
 v_NewDate.setDate(v_NewDate.getDate() + v_LeadTime);
 
If I use todays date (April 9, 2015), and v_LeadTime = 10, I receive the value "Tue Sep 26 2017 13:36:25 GMT-0500 (Central Daylight Time)".
 
Can someone explain what I am doing wrong?
 
Thanks
Link to comment
Share on other sites

Hello Scottster,

 

Could you please provide the whole script or the URL of your page?

 

I have tried with the following script:

<script>
var v_NewDate = new Date();
var v_LeadTime = 10;
v_NewDate.setDate(v_NewDate.getDate() + v_LeadTime);
alert(v_NewDate);
</script>

And I have got the correct date, April 21th.

Link to comment
Share on other sites

  • 2 weeks later...

function CalcArrivalDate()
{
var v_LeadTime = document.getElementById("InsertRecordLeadTime").value;
var v_ShipMethod = document.getElementById("InsertRecordShipMethod").value;

if (v_ShipMethod == "Ocean")
{
 var v_NewDate = new Date();
 v_NewDate.setDate(v_NewDate.getDate() + v_LeadTime);
 
 document.getElementById("InsertRecordEstimatedArrivalDate").value = v_NewDate;
}
}

Link to comment
Share on other sites

  • 3 years later...

Hi @Scottster,

You could try using the Calculated Value and use DATEDIFF formula for days just like this one: DATEDIFF(DAY, [@field:DateTime], GETDATE())

Caspio introduced new features which you can find here: https://howto.caspio.com/release-notes/caspio-bridge-13-0/ 
This release includes a new feature, Calculated Values in Submission Forms.  This allows you to generate calculations which you can use for you to get the number of days. 

 

I hope this helps!

Link to comment
Share on other sites

  • 2 years later...

Hello! I just wanted to share that we can add certain days in a calculated field or formula. You can try this formula: 

DateAdd(day, 30, [@field:date])

Then, it will now indicate the number of days that you inserted inside your formula. As you can see on my end, this is what it looks like: image.png.049826a65e122aa807df5e133c139f4c.png

image.png.0e1390623e030b8d083ba9f5c0bdee85.png

The Date add is the calculated field. The date from 6/1/2021 adds 30 days that is why it displays the 7/01/2021 date. 

I hope this helps! cheers! :D 

 

image.png

Edited by RuisiHansamu
Duplicated screenshot
Link to comment
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...
 Share

×
×
  • Create New...