Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Script Talk › Wrong values when accessing Date object
- This topic has 6 replies, 3 voices, and was last updated 3 years, 8 months ago by
Sam Moffatt.
-
AuthorPosts
-
March 16, 2022 at 4:39 AM #46989
Juan BorrásParticipantI set up a simple form with a Date field and a text field.
The text field is populated with:var sessionDate = record.getFieldValue(‘fld-6eb68cc954894bb79169fc40ac2705d7’);
var drDay = sessionDate.getDay();
var drMonth = sessionDate.getMonth();
var drYear = sessionDate.getFullYear();var dateresult = drDay + “/” + drMonth + “/” + drYear;
console.log(dateresult);
return dateresult;
When I choose bin the calendar picker: 20 Agu 2022, I got 6/7/2022 on the text field
Any ideas??
Thanks!
March 16, 2022 at 6:03 PM #46992
Sam MoffattParticipantAre you sure you have the right date field?
You should also be able to do
console.log(sessionDate);as well.March 19, 2022 at 10:14 AM #47010
Juan BorrásParticipantYes, it’s the right one. Find the attached captures below
Attachments:
You must be logged in to view attached files.March 19, 2022 at 2:06 PM #47014
Daniel LeuParticipantJavascript date handling is a bit confusing:
The
getDay()method returns the day of the week for the specified date according to local time, where 0 represents Sunday.The
getMonth()method returns the month in the specified date according to local time, as a zero-based value (where zero indicates the first month of the year).What you want to use is something like this:
var drDay = sessionDate.getDate(); var drMonth = sessionDate.getMonth() + 1; var drYear = sessionDate.getFullYear();-
This reply was modified 3 years, 8 months ago by
Daniel Leu.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksMarch 20, 2022 at 12:22 AM #47016
Juan BorrásParticipantThanks!
That was the problem!!
Now its working
March 20, 2022 at 9:50 AM #47017
Daniel LeuParticipantGreat that it works now for you!
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricksMarch 28, 2022 at 9:28 PM #47050
Sam MoffattParticipantI forget that dealing with dates in JS is so weird at times, I went looking and found a decent looking strftime port and threw it in my script manager repo as well.
-
This reply was modified 3 years, 8 months ago by
-
AuthorPosts
You must be logged in to reply to this topic.