Wrong values when accessing Date object

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk Wrong values when accessing Date object

Viewing 6 reply threads
  • Author
    Posts
  • March 16, 2022 at 4:39 AM #46989

    Juan Borrás
    Participant

    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!

    March 16, 2022 at 6:03 PM #46992

    Sam Moffatt
    Participant

    Are 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ás
    Participant

    Yes, 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 Leu
    Participant

    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.
    March 20, 2022 at 12:22 AM #47016

    Juan Borrás
    Participant

    Thanks!

    That was the problem!!

    Now its working

    March 20, 2022 at 9:50 AM #47017

    Daniel Leu
    Participant

    Great that it works now for you!

    March 28, 2022 at 9:28 PM #47050

    Sam Moffatt
    Participant

    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.

Viewing 6 reply threads

You must be logged in to reply to this topic.