SharePoint Online: How to Change Date Format to "DD/MM/YYYY"?

Requirement: Change Date format to "DD/MM/YYYY" in SharePoint Online.

How to Set Date Format in SharePoint Online?
By default, SharePoint Online sites display the dates in US format (MM/DD/YYYY). You may want to change the date format based on the country you live. Let's see how to set date format for a SharePoint Online site:
  • Open your SharePoint site in web browser
  • Click on Settings gear >> Click on Site settings
  • In Site settings page, Under Site Administration, click on "Regional settings" link.
  • Click on Locale drop down list arrow, and then select the locale to display dates. E.g. English United Kingdom
    sharepoint online change date format
    This changes the date format everywhere in the site. E.g. List, Columns including Created/Modified, Recycle bin, etc.
    change date format in sharepoint online
Pretty simple, huh? Well, The pain part is regional settings should be configured for each site (subsite)! Changing regional settings in the top level site doesn't automatically propagate the change in its subsites.

Change Date Format in SharePoint Online using PowerShell:
Here is how to change date format (locale) in SharePoint Online site using PowerShell
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Config parameters for SharePoint Online Site URL and Locale
$SiteURL = "https://crescenttech.sharepoint.com"
$LocaleID ="2057" #English - United Kingdom
 
#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
   
#Set up the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Ctx.Credentials = $credentials

#Get Regional Settings of the Web
$Web = $Ctx.Web
$Ctx.Load($web)
$Ctx.Load($Web.RegionalSettings)
$ctx.ExecuteQuery()
 
#Update the LocaleID of the site
$Web.RegionalSettings.LocaleId = $LocaleID
$Web.Update()
$Ctx.ExecuteQuery() 
Any new subsite you create will inherit the Regional Settings from its parent site!

Change Locale for All Sites in SharePoint Online Tenant
We can set the locale for all site sites in SharePoint Online - tenant wide using below PowerShell script. This script simply loops through all sites and changes the default locale. Just set $AdminSiteURL and $LocaleID variables in the script and provide the credentials to connect to SharePoint Online Admin center once.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#function to change Locale in regional settings of a SharePoint Online site
Function Set-SPOLocale([String]$SiteURL,[String]$LocaleID, [PSCredential]$Cred)
{ 
     Try
     {
        #Set up the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
   
        #Get Regional Settings of the Web
        $Web = $Ctx.Web
        $Ctx.Load($web)
        $Ctx.Load($Web.RegionalSettings)
        $ctx.ExecuteQuery()
 
        #Update the LocaleID of the site
        $Web.RegionalSettings.LocaleId = $LocaleID
        $Web.Update()
        $Ctx.ExecuteQuery()
 
        Write-host -f Green "Locale has been updated for "$Web.Url
 
        #Get all subsites of the web
        $Ctx.Load($Web.Webs)
        $Ctx.executeQuery() 
        #Iterate through each subsites and call the function recursively
        Foreach ($Subweb in $Web.Webs)
        {
            #Call the function to set Locale for the web
            Set-SPOLocale -SiteURL $Subweb.URL -LocaleID $LocaleID -Cred $Cred
        }
    }
    Catch [System.Exception]
    {
        Write-Host -f Red "Error:"$_.Exception.Message
    }
} 
 
#Config parameters for SharePoint Online Admin Center and Locale description
$AdminSiteURL = "https://crescenttech-admin.sharepoint.com"
$LocaleID ="2057"
 
#Get credentials to connect to SharePoint Online Admin Center
$Credentials = Get-Credential
 
#Connect to SharePoint Online Tenant Admin
Connect-SPOService -URL $AdminSiteURL -Credential $Credentials
 
#Get all Site Collections and Iterate through
Get-SPOSite -Limit ALL | ForEach-Object { 
    Set-SPOLocale -SiteURL $_.URL -LocaleID $LocaleID -Cred $Credentials
}
SharePoint Online: How to Change Date Format to "DD/MM/YYYY"? SharePoint Online: How to Change Date Format to "DD/MM/YYYY"? Reviewed by Salaudeen Rajack on June 09, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.