Get The Creation And Last Modified Date Of A Web Site Using JSOM

Summary:

This example is used to retrieve the creation date and modified date of a web site using JSOM

Content:

This article explores the web properties with the following code example, which displays the title, creation date and last modified date of a current site. Use the Gift for Developers from SharePoint article to insert the following code to the page. 
  1. <!-- How to get the Created date and Last Modified date of a Site -->  
  2. <!-- HTML Content -->    
  3. <div id="myapp"></div>    
  4. <!-- Script Content -->    
  5. <script type='text/javascript'>    
  6. var oWeb;    
  7. function getwebdetails()     
  8. {    
  9.     var clientContext = SP.ClientContext.get_current(); // equivalent to SPContext.Current    
  10.     oWeb = clientContext.get_web(); //Gets the current Web Object    
  11.     //clientContext.load(oWeb); - Load all properties for a web  
  12.     clientContext.load(oWeb,'Title''Created''LastItemModifiedDate');     
  13.     clientContext.executeQueryAsync(onSucceeded,onFailed);    
  14. }    
  15. function onSucceeded()    
  16. {    
  17.     var strmsg = "";  
  18.     strmsg += "<b>Web Title:</b> " + oWeb.get_title() +"<br/>";  
  19.     strmsg += "Created Date: "+ oWeb.get_created()+"<br/>";  
  20.     strmsg += "Last Modified Date: "+ oWeb.get_lastItemModifiedDate();  
  21.   
  22.     document.getElementById("myapp").innerHTML = strmsg;  
  23. }    
  24. function onFailed(sender, args)    
  25. {    
  26.     try    
  27.     {    
  28.         console.log('Error: ' + args.get_message());    
  29.     }     
  30.     catch (err)     
  31.     {    
  32.     }    
  33. }    
  34. ExecuteOrDelayUntilScriptLoaded(getwebdetails, "sp.js");    
  35. </script>  
Ebook Download
View all
Learn
View all