Global Developer Blog LightSwitch Howtos: Change the Date Format - Global Developer Blog - Site Home - MSDN Blogs

Global Developer Blog

The Global Developer Blog provides information to software developers and testers who are interested in international aspects of developer tools and technologies.

LightSwitch Howtos: Change the Date Format

LightSwitch Howtos: Change the Date Format

  • Comments 0

In this short blog, you will learn how to change the Date format in your Microsoft® Visual Studio® LightSwitch™ 2011 application.

By default, the Date format is controlled by the locale in your Control Panel. This will insure that the correct date format will be displayed to your user. Therefore you don’t have to worry about it.

As usual, you need to tweak and control our display. There are a couple of interesting means to adjust the date format.

 First, you can set the display to the long date format. This is accomplished by checking a checkbox in your display of while creating your date object. Check the below screenshot:

LightSwitch LongDate

Second, if you need more control over the date format. You can add a computed field, possibly a string, and on the calculate string, define your specific format. Follow these steps:

1)      Create a computed property called “CreateDateDisplay”

2)      Handle the “Compute” method.


LightSwitch Compute field

3)      Add your code, in the below example, I added code to use the US date formatting.

        partial void CreateDateDisplay_Compute(ref string result)

        {

 

            System.Globalization.CultureInfo cInfo;

            cInfo = new System.Globalization.CultureInfo("en-US");

            result = CreateDate.Date.ToString("d",cInfo);

        }

 

 

I hope you liked this post and check soon for more posts.

 

 

 

Leave a Comment
  • Please add 8 and 6 and type the answer here:
  • Post