I 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!
Are you sure you have the right date field?
You should also be able to do console.log(sessionDate);
as well.
Yes, it’s the right one. Find the attached captures below
Attachments:
You must be
logged in to view attached files.
Javascript 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 2 years, 8 months ago by Daniel Leu.
Great that it works now for you!
I 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.