Problem: Convert DateTime to Date
Approach 1:
Solution: Just create a date newInstance() and pass the year,month,day from the dateTime.
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);
How to extract date from timestamp field thru SOQL. example 2021-01-19T08:11:48.000Z o/p should be 2021-01-19
ReplyDelete