Master Posted June 3, 2015 Report Share Posted June 3, 2015 How can I add 10 days to record submit time so I can calculate expiration date? Quote Link to comment Share on other sites More sharing options...
MayMusic Posted June 3, 2015 Report Share Posted June 3, 2015 Add this code to the footer of the page. Make sure to replace "DATEFIELDNAME" with the field name you want to save this expiration date on <script> function f_date(){ var v_currentDate=new Date(); v_currentDate.setDate(v_currentDate.getDate() +10); var v_assignDate = (v_currentDate.getMonth() + 1) + "/" + v_currentDate.getDate() + "/" + (v_currentDate.getFullYear()); document.getElementById('InsertRecordDATEFIELDNAME').value = v_assignDate; } f_date(); </script> NaghmehK and MayMusic 2 Quote Link to comment Share on other sites More sharing options...
ababcock Posted October 16, 2015 Report Share Posted October 16, 2015 I would like my expiration date to be one year from the date entered (not necessarily today's date): Date Signed: 7/1/2015 Expiration Date: 7/1/2016 How would I adjust the javascript to accomplish that? Thanks! Quote Link to comment Share on other sites More sharing options...
ShelleyK Posted October 18, 2015 Report Share Posted October 18, 2015 In a submission form I have a field called Joined. This is a timestamp for the date of submission. I need to add one year to this time which is current day to this and have it reflect in the Expiration field. I have read and tried may things but nothing has worked. Thanks. Quote Link to comment Share on other sites More sharing options...
Xiang Posted October 27, 2015 Report Share Posted October 27, 2015 I would like my expiration date to be one year from the date entered (not necessarily today's date): Date Signed: 7/1/2015 Expiration Date: 7/1/2016 How would I adjust the javascript to accomplish that? Thanks! Hi Ababcock, How are you? How's the weather in your city? I think, this script can help: <SCRIPT LANGUAGE="JavaScript"> function setDate() { var stringDate = document.getElementById("InsertRecordDATE_SUBMIT").value; var myDate = new Date(Date.parse(stringDate)); myDate.setFullYear(myDate.getFullYear()+1); var myMonth = myDate.getMonth() + 1; if (myMonth<10) {myMonth = "0" + myMonth;} var myDay = myDate.getDate(); if (myDay<10) {myDay = "0" + myDay;} var myYear = myDate.getFullYear(); var result = myMonth + "/" + myDay + "/" + myYear; document.getElementById("InsertRecordEXPIRATION_DATE").value=result; } document.getElementById("caspioform").onsubmit=setDate; </SCRIPT> Don't forget to change names of fields, DATE_SUBMIT and EXPIRATION_DATE to names of yours fields. I'll be grateful, if you tell me if the code works. Have a nice day! Quote Link to comment Share on other sites More sharing options...
Xiang Posted October 27, 2015 Report Share Posted October 27, 2015 In a submission form I have a field called Joined. This is a timestamp for the date of submission. I need to add one year to this time which is current day to this and have it reflect in the Expiration field. I have read and tried may things but nothing has worked. Thanks. Hi Shelley, Welcome to our community! How are you? How's the weather in your city? "Timestamp" is set only when a record is added to a table, and the code cannot get the value of this parameter. If you have used alert to see the value of the field, it is "SYSDATE" until the record is created in the table. The "new Date();" method returns the current time, usually it's not worse than Timestamp. I hope, this code can help: <SCRIPT LANGUAGE="JavaScript"> function setDate() { var myDate = new Date(); myDate.setFullYear(myDate.getFullYear()+1); var myMonth = myDate.getMonth() + 1; if (myMonth<10) {myMonth = "0" + myMonth;} var myDay = myDate.getDate(); if (myDay<10) {myDay = "0" + myDay;} var myYear = myDate.getFullYear(); var result = myMonth + "/" + myDay + "/" + myYear; document.getElementById("InsertRecordsecond").value=result; } document.getElementById("caspioform").onsubmit=setDate; </SCRIPT> I'll be grateful, if you tell me if the code works. Have a nice day! Quote Link to comment Share on other sites More sharing options...
cva Posted December 4, 2015 Report Share Posted December 4, 2015 Hi Ababcock, How are you? How's the weather in your city? I think, this script can help: <SCRIPT LANGUAGE="JavaScript"> function setDate() { var stringDate = document.getElementById("InsertRecordDATE_SUBMIT").value; var myDate = new Date(Date.parse(stringDate)); myDate.setFullYear(myDate.getFullYear()+1); var myMonth = myDate.getMonth() + 1; if (myMonth<10) {myMonth = "0" + myMonth;} var myDay = myDate.getDate(); if (myDay<10) {myDay = "0" + myDay;} var myYear = myDate.getFullYear(); var result = myMonth + "/" + myDay + "/" + myYear; document.getElementById("InsertRecordEXPIRATION_DATE").value=result; } document.getElementById("caspioform").onsubmit=setDate; </SCRIPT> Don't forget to change names of fields, DATE_SUBMIT and EXPIRATION_DATE to names of yours fields. I'll be grateful, if you tell me if the code works. Have a nice day! Can someone adapt this script to be six months from the entered date instead of one year. Thank you.! Quote Link to comment Share on other sites More sharing options...
Xiang Posted December 5, 2015 Report Share Posted December 5, 2015 Can someone adapt this script to be six months from the entered date instead of one year. Thank you.! I can I have wrote more universal script, you can add days, months, and years. If you want add only month, set "0" for days and years. And do not forget to enter the name of your field instead of "NAME_OF_YOUR_FIELD" <SCRIPT LANGUAGE="JavaScript"> function setDate() { var plusDays = 0; var plusMonths = 6; var plusYears = 0; var fieldname = "NAME_OF_YOUR_FIELD"; var myDate = new Date(); myDate.setDate(myDate.getDate()+plusDays); myDate.setMonth(myDate.getMonth()+plusMonths); myDate.setFullYear(myDate.getFullYear()+plusYears); var myMonth = myDate.getMonth() + 1; if (myMonth<10) {myMonth = "0" + myMonth;} var myDay = myDate.getDate(); if (myDay<10) {myDay = "0" + myDay;} var myYear = myDate.getFullYear(); var result = myMonth + "/" + myDay + "/" + myYear; fieldname = "InsertRecord"+fieldname; document.getElementById(fieldname).value=result; } document.getElementById("caspioform").onsubmit=setDate; </SCRIPT> Have a nice day! Quote Link to comment Share on other sites More sharing options...
ababcock Posted December 6, 2015 Report Share Posted December 6, 2015 Hi Ababcock, How are you? How's the weather in your city? I think, this script can help: <SCRIPT LANGUAGE="JavaScript"> function setDate() { var stringDate = document.getElementById("InsertRecordDATE_SUBMIT").value; var myDate = new Date(Date.parse(stringDate)); myDate.setFullYear(myDate.getFullYear()+1); var myMonth = myDate.getMonth() + 1; if (myMonth<10) {myMonth = "0" + myMonth;} var myDay = myDate.getDate(); if (myDay<10) {myDay = "0" + myDay;} var myYear = myDate.getFullYear(); var result = myMonth + "/" + myDay + "/" + myYear; document.getElementById("InsertRecordEXPIRATION_DATE").value=result; } document.getElementById("caspioform").onsubmit=setDate; </SCRIPT> Don't forget to change names of fields, DATE_SUBMIT and EXPIRATION_DATE to names of yours fields. I'll be grateful, if you tell me if the code works. Have a nice day! Thank you, Xiang, that worked perfectly! Quote Link to comment Share on other sites More sharing options...
cva Posted December 7, 2015 Report Share Posted December 7, 2015 I can I have wrote more universal script, you can add days, months, and years. If you want add only month, set "0" for days and years. And do not forget to enter the name of your field instead of "NAME_OF_YOUR_FIELD" <SCRIPT LANGUAGE="JavaScript"> function setDate() { var plusDays = 0; var plusMonths = 6; var plusYears = 0; var fieldname = "NAME_OF_YOUR_FIELD"; var myDate = new Date(); myDate.setDate(myDate.getDate()+plusDays); myDate.setMonth(myDate.getMonth()+plusMonths); myDate.setFullYear(myDate.getFullYear()+plusYears); var myMonth = myDate.getMonth() + 1; if (myMonth<10) {myMonth = "0" + myMonth;} var myDay = myDate.getDate(); if (myDay<10) {myDay = "0" + myDay;} var myYear = myDate.getFullYear(); var result = myMonth + "/" + myDay + "/" + myYear; fieldname = "InsertRecord"+fieldname; document.getElementById(fieldname).value=result; } document.getElementById("caspioform").onsubmit=setDate; </SCRIPT> Have a nice day! Thank you for this. Its almost there. This add Six Months to current date. I would like to add Six Months to a date entered on a previous field on submit. Thank you Xiang Quote Link to comment Share on other sites More sharing options...
Xiang Posted December 7, 2015 Report Share Posted December 7, 2015 Thank you for this. Its almost there. This add Six Months to current date. I would like to add Six Months to a date entered on a previous field on submit. Thank you Xiang I am sorry Here the script code for the entered value: <SCRIPT LANGUAGE="JavaScript"> function setDate() { var plusDays = 0; var plusMonths = 6; var plusYears = 0; var dateFieldName = "Name_Of_the_field_with_Entered_date"; var fieldname = "Name_Of_the_field_with_Result_date"; dateFieldName = "InsertRecord" + dateFieldName; var entered_value = document.getElementById(dateFieldName).value; var myDate = new Date(entered_value); myDate.setDate(myDate.getDate()+plusDays); myDate.setMonth(myDate.getMonth()+plusMonths); myDate.setFullYear(myDate.getFullYear()+plusYears); var myMonth = myDate.getMonth() + 1; if (myMonth<10) {myMonth = "0" + myMonth;} var myDay = myDate.getDate(); if (myDay<10) {myDay = "0" + myDay;} var myYear = myDate.getFullYear(); var result = myMonth + "/" + myDay + "/" + myYear; fieldname = "InsertRecord"+fieldname; document.getElementById(fieldname).value=result; } document.getElementById("caspioform").onsubmit=setDate; </SCRIPT> Have a nice day! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.