0

In My sharepoint list i have a Duedate if type DateTime.Using Client object model when we fetch the value from this Field, it is displayed in the below format(Mon Jun 23 GMT+0530 2014).How to convert this in to MM/DD/yyy format?

<script type="text/javascript">

ExecuteOrDelayUntilScriptLoaded(getListItem, "sp.js");
function getListItem()
{

var itemId = getUrlVars()["ID"];

//alert(itemId);

var clientContext= SP.ClientContext.get_current();
var pList = clientContext.get_web().get_lists().getByTitle('Customer');

pListItem = pList.getItemById(itemId);

clientContext.load(pListItem, 'Title', 'DueDate');

clientContext.executeQueryAsync(Function.createDelegate(this, this.ExecuteOnSuccess), Function.createDelegate(this, this.myFailFunction));

}


function ExecuteOnSuccess(sender, args) 
{
ListDuedate=pListItem.get_item('DueDate');
alert(ListDuedate);
}

function myFailFunction() {
// do something to alert the user as to the error here.

alert('fail');
}

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
</script>

Thanks, Sandy

2 Answers 2

3

using moment.js

$(document).ready(function(){
 var d = new Date("Tue June 24 09:30:07 PDT 2014");
 $("#dDate").html(moment(d).format("DD/MM/YYYY"));

});

it is been answered in this post: Format Date (25 Jul) using Javascript Object Model

0

Oh my god it is so simple i have to split this.. I was able to achieve the same

 function convert(str) {
    var date = new Date(str),
        mnth = ("0" +(date.getMonth()+1)).slice(-1),
        day  = ("0" + date.getDate()).slice(-2);
    return [mnth, day,date.getFullYear() ].join("/");
}

Thanks, Sandy

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