locked
Cast only year from datetime field RRS feed

  • Question

  • Hi- Would like to cast only year from datetime datetype field in CRM 4.0. Want to display only YYYY in datetime datatype field.

    lets say;

    My Year :6/21/2011

    Want to display only year in same datetime attribute as : 2011 

     

    -mac


    Monday, June 20, 2011 8:33 PM

Answers

All replies

  • You will have to expose the date as a varchar (string) attribute on the form.  You won't be able to get a datetime field in CRM to just show the date.
    Jamie Miley
    http://mileyja.blogspot.com
    Linked-In Profile
    Follow Me on Twitter!
    Monday, June 20, 2011 9:08 PM
    Moderator
  • Please share some example.
    Monday, June 20, 2011 9:26 PM
  • I don't know that I have one on hand.  I have a lot of examples of jscript work on my blog (linked in my signature).

    You will want to not expose your main datetime attribute on the form or you may expose it if you wish, but you create another attribute that is only a varchar field.

    Then on load, on save, or on change of a field you can attach jscript that will obtain your datetime information.  You can pull it from the form field if you exposed it or you need to do a retrieve or retrievemultiple call into the CRM web service in order to pull the data back if you don't have the field exposed.  Then you can format the date in jscript and display it however you like in the varchar attribute field you did expose on the form.


    Jamie Miley
    http://mileyja.blogspot.com
    Linked-In Profile
    Follow Me on Twitter!
    Tuesday, June 21, 2011 12:29 AM
    Moderator