Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › how to use dateadd in a script
- This topic has 14 replies, 5 voices, and was last updated 4 years, 7 months ago by manish singh.
-
AuthorPosts
-
May 2, 2020 at 1:05 PM #40424
RainerParticipantHello, I am trying to add one hour to the value from a date time field
and put it into a variable recdate
here is what I’ve tried but I keep getting an error
any help would be appreciatedTry2() {
var call_date_id = ‘fld-9b94287517344436995393d16d0f5d7e’;
var mydate = record.getFieldValue(call_date_id);
var recdate = dateadd(mydate,0,0,0,0,1,0,0);
return recdate;
console.log(recdate);}
Try2();
returns error
-05-022020, 1:01:26 PM / Daily copy / Try2
Try2: ReferenceError: Can’t find variable: dateadd, line:(null)May 2, 2020 at 1:07 PM #40425
RainerParticipantsorry screwed up somehow
should befunction Try2() {
var call_date_id = ‘fld-9b9428751734443699539
3d16d0f5d7e’;
var mydate = record.getFieldValue(call_date_id);
var recdate = dateadd(mydate,0,0,0,0,1,0,0);
return recdate;
console.log(recdate);}
Try2();
May 2, 2020 at 3:27 PM #40426
RainerParticipantHello all
found a way to get this done with this script
I thought I’d post it here incase it helps someone elsefunction Try2() {
var call_date_id = ‘fld-9b94287517344436995393d16d0f5d7e’;
var mydate = record.getFieldValue(call_date_id);
var startdate = new Date(mydate);
var enddate = new Date(startdate);enddate.setHours((startdate.getHours() + 1));
console.log(enddate);
}
Try2();
May 4, 2020 at 10:35 AM #40449
Sam MoffattParticipantYou can use backticks to wrap your code (or use the code button in the editor) and it’ll preformat the content for you.
function Try2() { var call_date_id = ‘fld-9b94287517344436995393d16d0f5d7e’; var mydate = record.getFieldValue(call_date_id); var startdate = new Date(mydate); var enddate = new Date(startdate); enddate.setHours((startdate.getHours() + 1)); console.log(enddate); } Try2();
May 4, 2020 at 10:51 AM #40450
RainerParticipanthi Sam thanks for replying
is there something I’ve done wrong in my script?Sorry I’m very new to coding in javascript and I’m not sure what you mean
“You can use backticks to wrap your codethanks
RainerMay 4, 2020 at 2:59 PM #40452
Sam MoffattParticipantNothing wrong with the script, just saying you can format it a little better on the forum :)
May 4, 2020 at 6:05 PM #40455
RainerParticipantSorry I have actually never posted in any forum before
I thought a forum was a place to get help and share ideas
I assume you are talking about the empty lines in my code?
I’m new to coding and was just trying to help and unaware I would be critiqued by experts
So I’ve taken out the spaces and here it is. I hope this is better
In future I will refrain from posting :(function Try2() { var call_date_id = ‘fld-9b94287517344436995393d16d0f5d7e’; var mydate = record.getFieldValue(call_date_id); var startdate = new Date(mydate); var enddate = new Date(startdate); enddate.setHours((startdate.getHours() + 1)); console.log(enddate); } Try2();
May 4, 2020 at 10:24 PM #40457
Daniel LeuParticipantWhat Sam meant is if you put your code within backticks, it looks prettier here in the forum and it uses a font that makes it easier to see the code. It just helps all other visitors to better see what you did and learn from it as well!
There is nothing wrong with spaces in the code. It is very helpful to use as a visual mean of grouping things together or as a separation. Additionally, I commend you to post the solution to your question!
May 4, 2020 at 11:09 PM #40458
RainerParticipantHi thanks for the reply but I still don’t know what backpacks are
I thought he meant I should use backspace to remove the empty lines
I do a lot of cutting and pasting while I’m trying to figure things out
Hence the line spacesMay 4, 2020 at 11:13 PM #40459
RainerParticipantdarned autocorrect, I meant what backticks are
May 5, 2020 at 12:24 AM #40460
Sam MoffattParticipantBack ticks are the character on the far left of the standard US keyboard to the left of the one key. They’re this character:
`
. If you don’t have a US keyboard that has that character then you can just use the code buttons in the editor to put them in. When you do it, it wraps the code you put in the preformatted text which makes it a little easier to read.May 5, 2020 at 12:57 AM #40468
BrendanKeymasterHi Rainer,
Take a look at your post above again. I added the `
code
` back ticks to show you what your script looks like formatted nicely. Sam and Daniel were just trying to help so that it’s easier to read your code.Here’s an example of a single line piece of code with back ticks:
var first_name_id = 'fld-......';
and here’s a multi-line one:
var first_name_id = fld-.....'; var first_name = record.getFieldValue(first_name_id);
We’re all here to help and share ideas.
Thanks,
Brendan
May 5, 2020 at 11:07 PM #40484
RainerParticipantI apologize, I may have taken Sam’s comments in the wrong way.
I look forward to participating in the forums and learning from and helping others if I can
Thanks to Brendan and Daniel for their comments and helping me understand
Rainer
May 6, 2020 at 12:23 AM #40485
Sam MoffattParticipantNo need to apologise, I could have been a little less abstract. We all live and learn :) Welcome to the forum!
May 14, 2020 at 12:22 AM #40594
manish singhParticipanti think this will helpful to you
function Try2() {
var call_date_id = ‘fld-9b94287517344436995393d16d0f5d7e’;
var mydate = record.getFieldValue(call_date_id);
var startdate = new Date(mydate);
var enddate = new Date(startdate);enddate.setHours((startdate.getHours() + 1));
console.log(enddate);
}
Try2();
one of your friend already gave the same answer above, i got it from one of the tech blog
-
AuthorPosts
You must be logged in to reply to this topic.