getDate() is returning a strange value

2 followers Follow
Avatar
Nathan Waterman

I have a date field on my form set to 08/01/2018. The following code return 31 as the result of getDate() where it should return 1. Changing the date to 08/02/2018 returns 1 when it should be 2 etc. It's almost as if the functionality of getDate() has changed to mirror getMonth(); except in offline testing that isn't the case and works as expected.

 function futureDate (entryDate) {
var entry = new Date(entryDate);
var result = entry.getDate();
return result;
}
0

2 comments

Avatar
Junko Werner 1 vote

Hi Nathan,

I wonder if you are using a date-and-time field instead of a date field.

Since I noticed that depending on the time zone you set up on kintone's user account and the date-and-time field value, the argument that you pass from a date-and-time field after creating a Date object can be changed like in your case. Therefore, I would suggest using a date field if you are using date-and-time field now or try Moment.js to format the value of a date-and-time field instead of creating with a new Date object.

Here is the info about Moment.js.

▼ Moment.js - customize date formats

https://developer.kintone.io/hc/en-us/articles/115002348967-Moment-js-customize-date-formats

Regarding the different value in the test and production environment, if I put the same value on a date-and-time field, I got the same result.  Here is how I went to the test environment for your reference.

▼ Previewing an App

https://get.kintone.help/hc/en-us/articles/115001511268-Previewing-an-App

Thanks.

1
Avatar
Nathan Waterman 0 votes

Hi Junko,

Thanks for your help. I was able to get Moment.js to work and correctly format the date.

Thanks also for the preview tip!

0

Please sign in to leave a comment.