SharePoint – Change Date Format


Hello everyone. A while ago I got the request to change the date format of SharePoint. The company I´m working for has all SharePoint Site Collections setup using the Culture en-US and therefore the date format looks like this: MM/dd/yyyy. Since this date format can be quite confusing for our international employees we decided to replace it with the ISO8601 date format. The solution was quite simple:

Prerequisites:

  • Microsoft Visual Studio

The first thing you need to do is to create a new Console Application.

The next thing you need to to is to add a reference to sysglobl.dll.

And here is the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace DateTimeFormat
{
class Function
{
public void SetDateFormatISO8601()
{
try
{
CultureAndRegionInfoBuilder.Unregister("en-US");
}
catch
{
}

CultureAndRegionInfoBuilder builder = new CultureAndRegionInfoBuilder("en-US", CultureAndRegionModifiers.Replacement);
builder.LoadDataFromCultureInfo(new CultureInfo("en-US"));
builder.LoadDataFromRegionInfo(new RegionInfo("en-US"));
builder.GregorianDateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
builder.Register();
}

public void SetDateFormatAmerican()
{
try
{
CultureAndRegionInfoBuilder.Unregister("en-US");
}
catch
{
}

CultureAndRegionInfoBuilder builder = new CultureAndRegionInfoBuilder("en-US", CultureAndRegionModifiers.Replacement);
builder.LoadDataFromCultureInfo(new CultureInfo("en-US"));
builder.LoadDataFromRegionInfo(new RegionInfo("en-US"));
builder.GregorianDateTimeFormat.ShortDatePattern = "MM/dd/yyyy";
builder.Register();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DateTimeFormat
{
 class Program
 {
 static void Main(string[] args)
 {
 Function function = new Function();

 string Choice = string.Empty;
 Console.WriteLine("Set Date format of Site Collection:");
 Console.WriteLine("-----------------------------------");
 Console.WriteLine("1) Set Date format to ISO8601 standard format (yyyy-MM-dd)");
 Console.WriteLine("2) Set Date format to default american format (MM/dd/yyyy)");
 Console.WriteLine();
 Console.WriteLine("Choose a number:");
 Choice = Console.ReadLine();
 Console.WriteLine();

 if(Choice == "1")
 {
 function.SetDateFormatISO8601();

 Console.WriteLine("Done");
 Console.ReadLine();
 Console.WriteLine();
 }
 else if (Choice == "2")
 {
 function.SetDateFormatAmerican();

 Console.WriteLine("Done");
 Console.ReadLine();
 Console.WriteLine();
 }
 else
 {
 Console.WriteLine("Invalid input");
 Console.ReadLine();
 Console.WriteLine();
 }
 }
 }
}

That´s it. Your code is ready to use.

Please remember to run the code as Administrator. Otherwise the User Account Control will stop your program.

After you have successfully run the code you need to run cmd as Administrator and run the following command:

iisreset

That´s it. Now all Site Collections configured to use the Culture en-US will display their date format like this: yyyy-MM-dd.

Important: I did not come up with the code above. I just used the code I found here. The post was pretty useful for me so I thought I should share it.

I hope my post was useful for you and as always you can download my code from here.

Sources:

http://www.matdesmarais.com/2011/12/changing-the-date-display-format-in-sharepoint-2010/

Advertisements
Tagged ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: