Jump to content
  • 0

Adding 30 days to a timestamp field



I am attempting to insert a new date based on a timestamp field in my datapage. I have an active_date field and a deactive_field. When a user updates a record, I would like 30 days added to the date in the active_date field and store the results in the deactive_field. I had the following code developed, but it doesn't work properly. Any suggestions? FYI, the code is placed in the footer of the datapage.

function getDiff()


var v_sDate = document.getElementByName("EditRecordActivation_Date").value;

var sDate = new Date(v_sDate);

// converting the date in milliseconds

var milliSeconds = sDate.UTC();

// adding 30 days to the date

milliSeconds = milliSeconds + 2592000000;

// converting milliseconds back to date format

var dDate = new Date ( milliSeconds );

// converting date to string

finalDate = dDate.toDateString();

// storing the value in Deactivation_Date field



/* On submitting the webform, the function getDiff is executed */


Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Not sure why you are calling the element by name rather than id. If you post the URL in here, I can better help with troubleshooting.

Currently the syntax error is very obvious where you have:





Best practice if the Activation Date field is a text field:


Another question, is the Activation Date field a Timestamp? If so you can simply get the value of it by calling the timestamp parameter as:

var v_sDate = '[@cb:Timestamp]';

The next part of your code which does the milliseconds conversion I am not sure if is correct or not. There is again a better way of day conversion by setDate Java Script function. Here is an example http://www.w3schools.com/js/js_obj_date.asp, see the set date section which has an example like:

var myDate=new Date();


It simply adds 5 days to your date.

Hope this helps.


Bahar M.

Link to comment
Share on other sites

  • 0

First, Bahar, thanks for taking the time to review and respond to my issue. I am not a JS programmer, so this is very new to me. I paid someone to do this code, and this was what they provided. I researched the topics you mentioned, and tried to incorporate them on my own to no avail.

The app key is 832d1000721e233811cd46639add; however, I became so frustrated, I removed the code completely, and thought I would rework the date situation in FileMaker, in which I am highly proficient, as it would take me all of two seconds to construct a formula to update the deactivation_date automatically. Although this is not a solution I would prefer to use, as it will take away from the seamlessness of working with one application, it seems I may have no other alternative.

As a programmer, what I am seeking is not complicated at all, but when you don't know the syntax, it becomes challenging. Caspio wants to charge me $150.00 to provide the code, which I think is outrageous because I am not asking them to develop an application, but to help with what I think should be two or three lines of code.

In any event, I will review what you posted, and try my hands at it again, from your perspective.

Again, thank you for your support.

Link to comment
Share on other sites

  • 0

Hi there, I know it's been a little late but I just wanted to share that we can now add certain days in a 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.7fe8738c9a1fe3f02316d728d3150207.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. image.png.22ce9f135f374b56a3602e1bf4333219.png

I hope this helps! cheers! :D 

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.

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.

  • Create New...