I am reading sharepoint list item using java script and displaying content inside the content editor webpart text box, the date value in text box appears like below:
2014-09-06 00:00:00
I want to display the above date value like below:
09/06/2014 (dd/mm/yyyy)
How can I do this?
Here is my code:
document.getElementById("txtClaimDate").value=rows[0].getAttribute('ows_Claim_x0020_Date');
I am reading sharepoint list item using java script and displaying content inside the content editor webpart text box, the date value in text box appears like below:
2014-09-06 00:00:00
I want to display the above date value like below:
09/06/2014 (dd/mm/yyyy)
How can I do this?
Here is my code:
document.getElementById("txtClaimDate").value=rows[0].getAttribute('ows_Claim_x0020_Date');
Share
Improve this question
asked Jun 30, 2014 at 15:27
user1133737user1133737
1135 silver badges23 bronze badges
1
- You can use Date object to create a formatted string. – Teemu Commented Jun 30, 2014 at 15:31
3 Answers
Reset to default 3You could simply transform the date with javascript Date
var selectedDate = rows[0].getAttribute('ows_Claim_x0020_Date');
var check = function(n) {return (Number(n) < 10) ? "0" + n : String(n);}; //Used for leading 0
var date = new Date(selectedDate);
var delimiter = "/";
var newDate = check(date.getMonth() + 1) + delimiter + check(date.getDate()) + delimiter + date.getFullYear();
document.getElementById("txtClaimDate").value = newDate;
You can just parse the date ponents and put them back together as you wish:
var dateString = rows[0].getAttribute('ows_Claim_x0020_Date');
var ponents = dateString.split(/\D/); // Split on non-decimal characters
document.getElementById("txtClaimDate").value =
ponents[1] + "/" + ponents[2] + "/" + ponents[0];
It seems that SharePoint 2013 dynamically loads a script called MicrosoftAjax.js which prototypes a function called format on date objects. I'm guessing the documentation is similar to that of the C# version, but I can't say for sure.