Formatting of a date field in a script

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk Formatting of a date field in a script

Viewing 2 reply threads
  • Author
    Posts
  • January 26, 2021 at 5:11 PM #43299

    Victor Warner
    Participant

    In my form I have a number of fields of the date type with a date format of long (that is 27 January 2021). In a script I have included the date field, but the output is as follows: “Wed Jan 27 2021 00:00:00 GMT+0000 (GMT)”, for example:

    var hedd_verification = record.getFieldValue('fld-e7c386b5203a456dbaeb4755c6897a23');
    var hedd_verification_id = 'fld-e7c386b5203a456dbaeb4755c6897a23';
    
    var degree_level = record.getFieldValue('fld-04d88b9bf5c34cef8b2b488e4bccd67d');
    var degree_subject = record.getFieldValue('fld-e1c8f4bdea994a149cc338498c22e20e');
    var hedd_date_verification_sought = record.getFieldValue('fld-db9621fa80094bb9ac4fc2f68bcc2595');
    var hedd_date_verification_obtained = record.getFieldValue('fld-b7c0b62ed0514a15848e8cb32262b617');
    var gender = record.getFieldValue('fld-e6697b5fc0d24f328757592bf4362d4e');
    
    if (hedd_verification == 1) {
    
    	"and I verified that " + gender + " was awarded the " + degree_level + " in " + degree_subject + " by contacting HEDD (www.hedd.ac.uk, who are 'UK Higher Education's official service for candidate verification and university authentication') on " + hedd_date_verification_sought + " and receiving confirmation from HEDD of the award on " + hedd_date_verification_obtained
    } else {
    
    "but I have not verified that the degree certificate is genuine nor have I made any independent check as to its authenticity"
    }

    Is there a way to format the date in the script so that the date comes out as 27 January 2021 rather than “Wed Jan 27 2021 00:00:00 GMT+0000 (GMT)”?

    Any help would be gratefully received.

    January 26, 2021 at 5:54 PM #43300

    Daniel Leu
    Participant

    There are many ways to convert a date object into a format string in Javascript. Following works for me:

    var date = record.getFieldValue('fld-xxx');
    console.log(date.toLocaleDateString("en-GB", { year: 'numeric', month: 'long', day: 'numeric' }));

    Console:
    January 21, 2021

    January 28, 2021 at 1:19 AM #43305

    Victor Warner
    Participant

    Daniel,

    Thank you very much.

Viewing 2 reply threads

You must be logged in to reply to this topic.