Hi ,
As I had gone to search that how to separate hour and minute in apex , I was trying to search any method which could be return after decimal value so that I could calculate all values after decimal place as total number of minute and then extract the hour from total number of minute divide by 60 and separate again hour and minute !
Then I wrote some logic which is explained below !
We have a class contains two methods returnCheckDecimalValueForMin(string val) and returnCheckDecimalValueForHour(string hour) .
Now let say we have a list of decimal values like 34.46 , 34.56 , 45.57
so what we need to do actually to separate
As I had gone to search that how to separate hour and minute in apex , I was trying to search any method which could be return after decimal value so that I could calculate all values after decimal place as total number of minute and then extract the hour from total number of minute divide by 60 and separate again hour and minute !
Then I wrote some logic which is explained below !
We have a class contains two methods returnCheckDecimalValueForMin(string val) and returnCheckDecimalValueForHour(string hour) .
public class className {
public string returnCheckDecimalValueForMin(string dayVal){
string[] ss = new string[]{};
if(dayVal !='' && dayVal!=null){
if(dayVal.contains('.')){
string sss = dayVal.replace('.',',');
ss = sss.split(',');
return ss[1] ;
}else {
return dayVal ;
}
if(ss.size()>0){
return ss[1];
}else {return '';}
}else { return '';}
}
public string returnCheckDecimalValueForHour(string dayVal){
string[] ss = new string[]{};
if(dayVal !='' && dayVal!=null){
if(dayVal.contains('.')){
string sss = dayVal.replace('.',',');
ss = sss.split(',');
return ss[0] ;
}else {
return dayVal ;
}
}else { return '';}
}
}
Now let say we have a list of decimal values like 34.46 , 34.56 , 45.57
so what we need to do actually to separate
34+34+45 = 113 46+56+67 = 169 integer i = math.mod(169,60); integer returnHr = 169/60 ; Integer TotalHours = 113 + returnHr.intvalue(); Integer remainingMinutes = 169 - 60*returnHr.intvalue() ;
Nice
ReplyDeleteYaaron Studios is one of the rapidly growing editing studios in Hyderabad. We are the best Video Editing services in Hyderabad. We provides best graphic works like logo reveals, corporate presentation Etc. And also we gives the best Outdoor/Indoor shoots and Ad Making services.
video editors studio in hyderabad
short film editors in hyderabad
corporate video editing studio in hyderabad
ad making company in hyderabad
This is a clever solution for separating hour and minute values in Apex! The approach using string manipulation to handle decimal values is practical. As Salesforce continues to evolve, AI capabilities are being integrated into the platform, making skills like this even more valuable. For professionals looking to combine Salesforce expertise with AI knowledge, Gen AI and Agentic AI training near me in Electronic City offers comprehensive programs. Your logic for calculating total hours and remaining minutes works well for time-based calculations in Salesforce applications. The mathematical approach (mod and division) is clean and efficient. This kind of practical code is exactly what Salesforce developers need for real-world projects. Great share!
ReplyDelete