1

I have the following code to get values of a column.

function GetKPIS(EstruturaKPI){
jQuery.ajax({
    url: "SITE/_api/web/lists/GetByTitle('KPI')/items?$filter=Title eq '" + EstruturaKPI + "'",
    method: "GET",
    headers: {
        "Accept": "application/json; odata=verbose"
    },
    success: function (data) {

        jQuery.each(data.d.results, function(key, value){

            var UltimaData = (value.Data);


        })
    },
    error: function (error) {
        console.log(error);
    }
});

With this code, I am able to get the DATE the user has input into the field. The problem is, the date is shown in YYYY-MM-DDZ(time), and I wanted the date to show DD-MM-YYYY ONLY (Without the time).

How can I achieve this?

Thank you so much

  • is your date column name Data? – harshal gite Oct 2 at 17:39
  • @harshalgite yes. Yes, it is. – João Oct 3 at 7:54
2

You can use the below code or use third-party js like moment to format dates.

function GetKPIS(EstruturaKPI){
    jQuery.ajax({
        url: "SITE/_api/web/lists/GetByTitle('KPI')/items?$filter=Title eq '" + EstruturaKPI + "'",
        method: "GET",
        headers: {
            "Accept": "application/json; odata=verbose"
        },
        success: function (data) {

            jQuery.each(data.d.results, function(key, value){
                var date = new Date(value.Data); //assuming this is your date field
                var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
                var month = date.getMonth() < 10 ? '0' + date.getMonth() : date.getMonth();
                var year = date.getFullYear();

                var UltimaData = day + "-" + month + "-" + year;
            })
        },
        error: function (error) {
            console.log(error);
        }
    });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.