Date format in Formula field and Apex in Salesforce


Format YYYY/MM/DD in formula field

TEXT(YEAR(DATEVALUE(Date__c) ))+ "/" +TEXT(MONTH(DATEVALUE(Date__c) ))+ "/" +TEXT(DAY(DATEVALUE(Date__c)))


Format MM/DD/YYYY in formula field

TEXT(MONTH(Date__c))+ "/" + TEXT(DAY(Date__c))+ "/" + TEXT(YEAR(Date__c))


Format DD/MM/YYYY in formula field

TEXT(DAY(Date__c))+ "/" +TEXT(MONTH(Date__c))+ "/" +TEXT(YEAR(Date__c))


Convert to String in APEX

1
2
Date myDate = Date.today();
String newFormat = myDate.year() + '/' + myDate.month() + '/' + myDate.day();


Convert using format() in APEX

1
2
DateTime dt = DateTime.now();
String newFormat = dt.format('yyyy/MM/dd hh:mm:ss');


 If you have any question please leave a comment below.

If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Thanks
Keep Coding 



Post a Comment

2 Comments

  1. how to carate a blog in bologger.com please help me

    ReplyDelete
    Replies
    1. This link might help
      https://www.youtube.com/watch?v=5n-ZpBo7cHI

      Delete