Update single line text with date picker field value

Hi @Margo @Nikita_Kurguzov

I am trying to Update a single line text field with the value from a date picker field. At the moment I am getting the return value as day month year time etc - I only want the date format yyyy-mm-dd returned and not the time and time zone

This is the current format I am receiving it in

I want it to look like
image

Kind regards,

Hello @Dina_Louw,

You must use the toISOString() method to convert date to the standard format. Then, you can format the date as you like:

 var date = new Date().toISOString().split('T')[0]
var formattedDate = date.replace(/-/g, "/")

Hi @Margo

This is the code I have at the moment.

fd.spRendered(function() {

fd.field('Title').disabled = true;
fd.field('Sales_x0020_Date').disabled = true;

fd.field('Sales_x0020_Date').value;
var today = new Date();
var minusDate = today.setDate(today.getDate()-1);
fd.field('Sales_x0020_Date').value = new Date(minusDate);

var date = new Date().toISOString().split('T')[0]
var formattedDate = date.replace(/-/g, "/")
fd.field('Date1').value = new Date(formattedDate);


function combine () {

    if (fd.field('BranchNo').value != null && fd.field('Date1').value != null) {

        fd.field('Title').value = fd.field('BranchNo').value + '-' + fd.field('Date1');
    }

    else {
        //Clear PositionWeek field value if one of the dropdowns is cleared
        fd.field('Title').value = '';
    }
}
//Call function on form load
combine ();

//Call function on field change
fd.field('BranchNo').$on('change', combine);
fd.field('Date1').$on('change', combine);

});

The form is bringing the Date1 value up as [Object Object]

I am getting the Title field data from a field called BranchNo (Number field), then I take the date value that is in my Sales Date (Date) and copying it to the Date1 and Date2 column. Then I try to convert the Date1 field to ISOString and copy it to the Title field - Title field needs to = BranchNo-Date1 and is not working at the moment. Am I missing something in my code???

@Dina_Louw,

The code I've shared is for converting the date to a string in the desired format. You msut use it for the text field like so:

var date = new Date().toISOString().split('T')[0]
var formattedDate = date.replace(/-/g, "/")
d.field('Title').value = fd.field('BranchNo').value + '-' + formattedDate;