none
how to format datetime property in view?

    Question

  • Hi,

    How to format datetime property in view? I have a Start Date property column and I want to remove the time in it.

    Ex. 06/29/2011 16:00:00.000 the value should be 06/29/2011

     

    Thanks,

    Zel

    Monday, June 13, 2011 7:11 AM

Answers

  • It can be done, but you need to modify some XML. Short Answer: In your View definition, find the <mux:Column> node that's bound to the date/time property you want to re-format. In the DisplayMemberBinding you can simply add a StringFormat=d option. For example:

    <mux:Column Name="$TimeAdded$" DisplayMemberBinding="{Binding Path=$TimeAdded$}" Width="100" DisplayName="TimeAdded.View.DisplayName" Property="$TimeAdded$" DataType="s:DateTime" />
    

    is changed to

    <mux:Column Name="$TimeAdded$" DisplayMemberBinding="{Binding Path=$TimeAdded$, StringFormat=d}" Width="100" DisplayName="TimeAdded.View.DisplayName" Property="$TimeAdded$" DataType="s:DateTime" />
    


    Notice that the DisplayMemberBinding property has ", StringFormat=d" added to the binding function. Once you reimport the MP, you'll probably need to restart the console. Once you do, you'll see that the time is no longer visible in the view column.

     

     

    Long answer (if you haven't dealt with modifying an XML file directly yet)

    First, obviously, you'll need to know which management pack your view is stored in (hopefully it's an unsealed MP!)

    If you don't have a copy you can modify, export the management pack and open it with your favorite xml editor (personally, I still use notepad :) )

    In the MP you will find a node called <Views>. Somewhere in there you can find your view. If you created this view in the console it will have a screwy ID that makes it hard to distinguish from other IDs. So, do a search for the display name (or title) of your view. You'll find it in a DisplayString node. The ElementID value is what you're looking for. Now do a search for that ElementID (it'll be View.blahblahblah) and you'll find the view you need to modify.

    In that view node, you'll find some <mux:Column> nodes. Each of these nodes will have a DisplayMemberBinding property that have a value that looks something like {Binding Path=StartDate}. StartDate is actually the name of your Start Date property. Change that DisplayMemberBinding value to include a StringFormat=d option. For example {Binding Path=StartDate, StringFormat=d}.

    Give that a try and see if it works for you :)

    Monday, June 13, 2011 8:16 PM

All replies

  • It can be done, but you need to modify some XML. Short Answer: In your View definition, find the <mux:Column> node that's bound to the date/time property you want to re-format. In the DisplayMemberBinding you can simply add a StringFormat=d option. For example:

    <mux:Column Name="$TimeAdded$" DisplayMemberBinding="{Binding Path=$TimeAdded$}" Width="100" DisplayName="TimeAdded.View.DisplayName" Property="$TimeAdded$" DataType="s:DateTime" />
    

    is changed to

    <mux:Column Name="$TimeAdded$" DisplayMemberBinding="{Binding Path=$TimeAdded$, StringFormat=d}" Width="100" DisplayName="TimeAdded.View.DisplayName" Property="$TimeAdded$" DataType="s:DateTime" />
    


    Notice that the DisplayMemberBinding property has ", StringFormat=d" added to the binding function. Once you reimport the MP, you'll probably need to restart the console. Once you do, you'll see that the time is no longer visible in the view column.

     

     

    Long answer (if you haven't dealt with modifying an XML file directly yet)

    First, obviously, you'll need to know which management pack your view is stored in (hopefully it's an unsealed MP!)

    If you don't have a copy you can modify, export the management pack and open it with your favorite xml editor (personally, I still use notepad :) )

    In the MP you will find a node called <Views>. Somewhere in there you can find your view. If you created this view in the console it will have a screwy ID that makes it hard to distinguish from other IDs. So, do a search for the display name (or title) of your view. You'll find it in a DisplayString node. The ElementID value is what you're looking for. Now do a search for that ElementID (it'll be View.blahblahblah) and you'll find the view you need to modify.

    In that view node, you'll find some <mux:Column> nodes. Each of these nodes will have a DisplayMemberBinding property that have a value that looks something like {Binding Path=StartDate}. StartDate is actually the name of your Start Date property. Change that DisplayMemberBinding value to include a StringFormat=d option. For example {Binding Path=StartDate, StringFormat=d}.

    Give that a try and see if it works for you :)

    Monday, June 13, 2011 8:16 PM
  • You're a star Aaron, I'd been meaning to find that one out for a while but it was low on my to do list.

    Into my tips and tricks bag it goes ;)


    My System Center Blog
    Tuesday, June 14, 2011 7:43 PM