Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Devops
  3. Question
Devops

How to format date to Yyyyy-MM-Dd through Apex?

Asked by Diana Campbell Jul 25, 2023 673 views 1 answer
Share

About this question

I am creating dynamic SOQL query for the search page with the below-mentioned code: VFP

Apex:
My Invoice_Date__c is a date field in the object
If I execute the following code in Anonymous window I do see the correct format but with my building dynamic SOQL I see the 2017-07-17 00:00:00
Date d = s.Invoice_Date__c; string dateStr = DateTime.newInstance(d.year(),d.month(),d.day()).format('yyyy-MM-dd'); system.debug('//' + dateStr);
Dynamic query building:
if (s.Invoice_Date__c != null) { Datetime d = s.Invoice_Date__c; String dateOutput

Despite selecting today’s date , in debug its displaying another date. How to format date to Yyyyy-MM-Dd through Apex?

Your answer

1 Answer

More Devops discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest DevOps Blogs

Guides, tips and career advice on DevOps from JanBask experts.