Date and Time Format Pattern in LightSwitch 2012

This article describes how to use the Date Time Datatype in LightSwitch Visual Studio 2012.

The following is the procedure to create a sample of using the Date Time datatype on a Screen.

Step 1

Open the LightSwitch Application in Visual Studio 2012 and go to the Solution Explorer.

Solution Explorer

Right-click on "Data Source" and choose "Add Table".

Add Table

The table appears in the table designer window. Insert the records in the following table.

Student Table

Here in the table I have added a record named "DOB" and I have taken its datatype as "Date Time" as shown below.

Select DOB from table

Step 2

From the table select the "DOB" record and go to the property window
of the DOB record.

Select DOB from table

Go to the Format Pattern property under the formatting section in the property window and enter "M" in Format Pattern TextBox as shown below.

Property Window With M format

Step 3

Now once again go to the Solution Explorer, right-click on "Screens" and choose "Add Screen".

Add Screen

The Add New Screen dialog box appears. Select the "Editable Grid Screen" from the Screen Template, inside screen information, choose "Student" under screen data and provide a name to the Screen and click the "OK" button.

Add New Screen

The Screen Designer appears as shown below.

Application Designer

Step 3

Press F5 to run the application. Provide the information and we will see the date in the following format pattern as shown below.

Date Time Output using M-Format

Step 4

Stop debugging the application.

Once again go to the Property window of "DOB" in the Table Designer and this time enter "G" in the Format Pattern of the property window. 

Property Window With G format

Step 5

Once again press F5 to run the application. This time we will see the date in the following pattern as shown below.

G Format Type Output

Note that the Date Time Picker and the Date Time Viewer control will ignore the Format Pattern property. Only the TextBox and the Label control will follow this property.

To learn more
 Format Pattern, see Date and Time Format Pattern.


Similar Articles