Thursday 13 February 2014

Converting DateTime to Date in Salesforce


Problem: Convert DateTime to Date 

Approach 1:

Solution: Just create a date newInstance() and pass the year,month,day from the dateTime.

Here is the Code,

1.    DateTime dt = System.now();
2.    Date myDate = date.newinstance(dt.year(), dt.month(), dt.day());
3.    System.debug('My date is-----'+myDate);

Approach 2:

Solution: Convert DateTime to Date using Date() method.

Here is the Code,

1.    DateTime dt = System.now()
2.    Date myDate= dt.date();
3.    System.debug('My date is-----'+myDate);


2 comments:

  1. How to extract date from timestamp field thru SOQL. example 2021-01-19T08:11:48.000Z o/p should be 2021-01-19

    ReplyDelete
  2. Hello Everyone,

    Welcome to the future! Financing made easy with Prof. Mrs. DOROTHY LOAN INVESTMENTS

    Have you been looking for financing options for your new business plans, Are you seeking for a loan to expand your existing business, Do you find yourself in a bit of trouble with unpaid bills and you don’t know which way to go or where to turn to? Have you been turned down by your banks? MRS. DOROTHY LOAN INVESTMENTS says YES when your banks say NO. Contact us as we offer financial services at a low and affordable interest rate of 2% for long and short term loans. Interested applicants should contact us for further loan acquisition procedures via profdorothyinvestments@gmail.com

    Services rendered include:

    *Refinancing Loans
    * Car Loan
    *Truck Loans
    * Home Loan
    * Mortgage Loan
    * Debt Consolidation Loan
    * Business Loan [secure and unsecured]
    * Personal Loan [secure and unsecured]
    * Students Loan and so many others.

    For more info; Contact us via Email: profdorothyinvestments@gmail.com

    With Prof. Mrs. DOROTHY LOAN INVESTMENTS. you can say goodbye to all your financial crisis and difficulties as we are certified, trustworthy, reliable, efficient, fast and dynamic

    ReplyDelete

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...