0

enter image description hereenter image description hereCurrently the below code gives me a date display of: 2019-01-31 00:00:00. I would like to see it displayed as: 31 January 2019 instead...

<table width="35%" align="left" id="myHTMLTable" border="0" cellspacing="0" cellpadding="0"> 
<tbody>
  <tr align="Middle"> 
     <td>
        <b><span style="font-size: 18pt;">Due Date</span></b></td> 
  </tr>
  <tr align="middle">
     <td align="Middle">
        <span style="color: #548235; font-size: 25pt;">2019-01-31 00:00:00</span></td>
  </tr>
</tbody>
</table> 

getMyListData() ;
function getMyListData()
{                     
    var method = "GetListItems";                 
    var webURL =  $().SPServices.SPGetCurrentSite() ;                     
    var list = "Project Statement";                      

    var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Name' /><Value IncludeTimeValue='FALSE' Type='DateTime'>2008-12-03T12:00:00Z</Value>" + "</ViewFields>";

    var query = "<Query><OrderBy><FieldRef Name='Date_x0020_Due' /></OrderBy></Query>"; 

    $().SPServices
    ({
         operation: method,
         async: false, 
         webURL: webURL,
         listName: list,
         CAMLViewFields: "<ViewFields Properties='True' />",
         CAMLQuery: query,                                                                                     
         completefunc: function (xData, Status)
         {
             $(xData.responseXML).SPFilterNode("z:row").each(function() 
             {
                 var vDueDate = $(this).attr("ows_Date_x0020_Due");

                 $("#myHTMLTable").append("<tr align='middle'>" +
                    "<td align='Middle'>"+"<span style='font-size:25.0pt;color:#548235'>"+vDueDate+"</span>"+"</td>" + 
                 "</tr>");
             });
         }
    });
};

Could not get code in correctly, so hope you can understand it.

0

They are various ways to format the dates using plugins or custom functions. I will answer it using plain javascript. Use below code in your completefunc:

var monthsArray = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

$(xData.responseXML).SPFilterNode("z:row").each(function() 
{
    var owsDueDate = $(this).attr("ows_Date_x0020_Due").replace(' ' , 'T') + "Z";
    var date = new Date(owsDueDate);
    var dd = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();
    var vDueDate =  dd + " " + monthsArray[m] + " " + y;

    $("#myHTMLTable").append("<tr align='middle'><td align='middle'><span style='font-size:25pt;color:#548235'>"+vDueDate+"</span></td></tr>");
});
  • I replaced what I had with what you provided, but now it does not show a date at all. Not sure how to add code to a comment. I'm not a very good programmer. – drcoz Nov 19 '18 at 18:23
  • On the line var vDueDate is there suppose to be two "=="? When I remove one of them I get "NaN undefined NaN". With the two equal signs I don't get anything. – drcoz Nov 19 '18 at 18:43
  • "==" was by mistake. It should be single "=". try logging each variable in console and see the what is the value of variable. For example. console.log(owsDueDate);. It will give you an idea where the code is wrong. – Ganesh Sanap Nov 19 '18 at 19:54
  • I don't have full code right now. Will post it tomorrow. – Ganesh Sanap Nov 19 '18 at 19:55
  • 1
    That worked.... – drcoz Nov 22 '18 at 15:48

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.