There are two methods to get date from DateTime
- By Date Instance : Here we will get date by Date.newInstance() method
Public Class DatetimetoDateConversion{
public static void dateTimeToDate(){
DateTime dtime = System.now();
Date d = Date.newInstance(dtime.year(), dtime.month(), dtime.day());
System.debug('Date==>' + d);
}
}
2. By Date Method: Here will get the Date by Apex Date() method
Public Class DatetimetoDateConversion{
public static void dateTimeToDate(){
DateTime dtime = System.now();
Date d = dt.date();
System.debug('Date==>' + d);
}
}
What’s your Reaction?
+1
+1
+1
+1
1
+1
+1
3
2 comments
I used to be recommended this web site by my cousin. I am now not positive whether
this post is written through him as nobody else know such particular approximately my
problem. You are wonderful! Thanks!
Thanks @Tarah keep reading