Skip to content

Instantly share code, notes, and snippets.

@sksnips
Created December 24, 2015 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sksnips/af70704d30b4b3ce5779 to your computer and use it in GitHub Desktop.
Save sksnips/af70704d30b4b3ce5779 to your computer and use it in GitHub Desktop.
HTML snippet is used to retrieve the creation date and modified date of a web site using JSOM
<!-- How to get the Created date and Last Modified date of a Site -->
<!-- HTML Content -->
<div id="myapp"></div>
<!-- Script Content -->
<script type='text/javascript'>
var oWeb;
function getwebdetails()
{
var clientContext = SP.ClientContext.get_current(); // equivalent to SPContext.Current
oWeb = clientContext.get_web(); //Gets the current Web Object
//clientContext.load(oWeb); - Load all properties for a web
clientContext.load(oWeb,'Title', 'Created', 'LastItemModifiedDate');
clientContext.executeQueryAsync(onSucceeded,onFailed);
}
function onSucceeded()
{
var strmsg = "";
strmsg += "<b>Web Title:</b> " + oWeb.get_title() +"<br/>";
strmsg += "Created Date: "+ oWeb.get_created()+"<br/>";
strmsg += "Last Modified Date: "+ oWeb.get_lastItemModifiedDate();
document.getElementById("myapp").innerHTML = strmsg;
}
function onFailed(sender, args)
{
try
{
console.log('Error: ' + args.get_message());
}
catch (err)
{
}
}
ExecuteOrDelayUntilScriptLoaded(getwebdetails, "sp.js");
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment