Function to get difference in time as HOURS and MINUTES - acumatica

trying to get the time difference from when a sales order was created and when it was shipped. The only function I could get was DateDiff.
Is it possible to get the time in the format of “HOUR:MINUTE”?
=DateDiff( 'MINUTE',[SOShipment.ConfirmedDateTime],[SOOrder.CreatedDateTime])*-1

You can use do a simple calculation to get your output like this in C#.
DateTime a = DateTime.Now;
DateTime b = DateTime.Now.AddDays(10).AddHours(6).AddMinutes(10);
Console.WriteLine ("Created Date: " + a);
Console.WriteLine ("Shipped Date: " + b);
Console.WriteLine ("Days difference: " + (b - a).Days);
Console.WriteLine ("Hours difference: " + (b - a).Hours);
Console.WriteLine ("Minutes difference: " + (b - a).Minutes);
Console.WriteLine ("Difference in hours and minutes: " + (((b - a).Days * 24) + (b - a).Hours) + ":" + (b - a).Minutes);
Output of above code:

Related

How can I format this String with double x,y,total to two decimal places. output = (x + " + " + y + " = " + total);

How can I format this String with double x,y,total to two decimal places. String output = (x + " + " + y + " = " + total);
String ouput = String.format("%.2f + %.2f = %.2f",x,y,total);
System.out.println(output);
will give you the output with 2 decimal places or you can use DecimalFormat as well.

convert my string to AM or PM hour in ActionScript 3

I've got a String variable for my time :
var $myTime:String;
//Some calculation
trace(myTime);
// Result is : 14:25 (for example)
I'm looking for a way to convert this string ("14:25" in this example) to a simple AM / PM format.
So in this example it would be, for example, 2 PM
Any idea how I can simply do that ?
You can use DateFormatter class to set your wished pattern.
You can write your code as follow:
var df:DateFormatter = new DateFormatter();
df.formatString = "YYYY-MM-DD L:NN:SS";
df.format(myTime);
Where L is HOUR with PM/AM; NN are the minutes SS seconds.
You can see the complete guide, about DateFormatter pattern, here
var myTime:Date = new Date();
var timeString:String;
if (myTime.getHours() > 12)
{
timeString = String((myTime.getHours() - 12) + ":" + myTime.getMinutes() + " PM");
}
if (myTime.getHours() == 12)
{
timeString = String(myTime.getHours() + ":" + myTime.getMinutes() + " PM");
}
if (myTime.getHours() < 12)
{
timeString = String(myTime.getHours() + ":" + myTime.getMinutes() + " AM");
}
trace(timeString);
That should do the trick.

Cron expression with start and end time

I am trying to write an cron expression with a specific start time and end time everyday. i.e.
every minute from 10:15 to 17:35 everyday
One possible solution for this is writing 3 different cron expressions like this:
0 15-59 10 * * *
0 * 11-17 * * *
0 0-35 17 * * *
Is there any possible way to write this in one single cron expression ?
There is no other way to achieve it using single crone expression but to specify multiple crone expressions for specific startDate and endDate.
There is a slight modification in second crone expression though (highlighted one)
0 15-59 10 * * * (Every minute between 10:15 AM and 10:59 AM)
0 * 11-16 * * * (Every minute, between 11:00 AM and 04:59 PM)
0 0-35 17 * * * (Every minute between 05:00 PM and 05:35 PM)
Quartz Scheduler c#
run job between to hours
use corn mask:
ITrigger trigger_1 = TriggerBuilder.Create()
.ForJob("YOUR_JOB")
.WithIdentity("trigger_1")
.StartAt(startTime)
.WithCronSchedule("0 0/1 8-13 ? * SUN,MON,TUE,WED,SAT *")
.Build();
use Quartz Schedule:
trigger_1 = TriggerBuilder
.Create()
.ForJob("YOUR_JOB")
.WithIdentity("trigger_1")
.StartAt(startTime)
.WithDailyTimeIntervalSchedule(c => c
.OnEveryDay()
.WithIntervalInMinutes(1).WithRepeatCount(1)
.StartingDailyAt(new TimeOfDay(08, 30))
.EndingDailyAt(new TimeOfDay(12, 30))
)
.Build();
HashMap<String, String> weekday = new HashMap<>();
// String strDays ="[Monday, Friday]";
String strCalDay = "";
String startDate[] = fromDate.split("-");
String endDate[] = toDate.split("-");
weekday.put("MONDAY", "1");
weekday.put("TUESDAY", "2");
weekday.put("WEDNESDAY", "3");
weekday.put("THURSDAY", "4");
weekday.put("FRIDAY", "5");
weekday.put("SATURDAY", "6");
weekday.put("SUNDAY", "7");
strDays = strDays.replace("[", "").replace("]", "");
String strDay[] = strDays.trim().toUpperCase().split(",");
if (strDay != null && strDay.length > 0) {
for (int i = 0; i < strDay.length; i++) {
strCalDay = strCalDay + "," + weekday.get(strDay[i].trim().replace("\"", ""));
}
// System.out.println(" No of days :: "+ strCalDay);
strCalDay = strCalDay.replaceFirst(",", "");
//System.out.println(" No of days :: "+ strCalDay);
}
Calendar startCal = Calendar.getInstance(TimeZone.getDefault());
Calendar endCal = Calendar.getInstance(TimeZone.getDefault());
startCal.set(Integer.parseInt(startDate[0].toString()),
Integer.parseInt(startDate[1].toString()),
Integer.parseInt((startDate[2].toString())));
endCal.set(Integer.parseInt(endDate[0].toString()),
Integer.parseInt(endDate[1].toString()),
Integer.parseInt((endDate[2].toString())));
int yearsInBetween = endCal.get(Calendar.YEAR) - startCal.get(Calendar.YEAR);
int monthsDiff = endCal.get(Calendar.MONTH) - startCal.get(Calendar.MONTH);
long ageInMonths = yearsInBetween * 12 + monthsDiff;
System.out.println(" ageInMonths: " + ageInMonths);
if (startCal.get(Calendar.MONTH) != endCal.get(Calendar.MONTH)) {
if (ageInMonths == 3) {
Calendar middleMonth1 = (Calendar) startCal.clone();
middleMonth1.add(Calendar.MONTH, 1);
Calendar middleMonth2 = (Calendar) startCal.clone();
middleMonth2.add(Calendar.MONTH, 2);
int getFirstMMonth = middleMonth1.get(Calendar.MONTH);
int getSecMMonth = middleMonth2.get(Calendar.MONTH);
if (getFirstMMonth == 0) {
getFirstMMonth = 12;
System.out.println(" getFirstMMonth : " + getFirstMMonth);
}
if (getSecMMonth == 0) {
getSecMMonth = 12;
// System.out.println(" getSecMMonth : " +getSecMMonth );
}
exp = strTimeMin + " " + strTime + " " + startDate[2] + "-" + "31,1-31,1-31,1-" + endDate[2] + " " +
startDate[1] + "," + getFirstMMonth + "," + getSecMMonth + "," + endDate[1] + " *";
// System.out.println(" expression for month3 : " + exp);
}
if (ageInMonths == 2) {
Calendar middleMonth1 = (Calendar) startCal.clone();
middleMonth1.add(Calendar.MONTH, 1);
//System.out.println(" get middleDate month : " + middleMonth1.get(Calendar.MONTH));
int getMiddleMonth = middleMonth1.get(Calendar.MONTH);
if (getMiddleMonth == 0) {
getMiddleMonth = 12;
// System.out.println(" getMiddleMonth : " +getMiddleMonth );
}
// System.out.println(" Outside getMiddleMonth : " +getMiddleMonth );
endCal.set(Calendar.MONTH, 11);
//System.out.println(" get middleDate month 001: " + endCal.get(Calendar.MONTH));
exp = strTimeMin + " " + strTime + " " + startDate[2] + "-" + "31,1-31,1-" +
endDate[2] + " " + startDate[1] + "," +
getMiddleMonth + "," + endDate[1] + " *";
// System.out.println(" get end month2 : " + exp);
} else if (ageInMonths == 1) {
exp = strTimeMin + " " + strTime + " " + startDate[2] + "-31,1-" +
endDate[2] + " " + startDate[1] + "," + endDate[1] + " *";
//System.out.println(" expression for one month : " + exp);
}
} else {
exp = strTimeMin + " " + strTime + " " + startDate[2] + "-" + endDate[2] + " " + endDate[1] + " *";
}
System.out.println(" expression for before parameter : " + exp);
//Run with only Start Date
if (strRepeat != null && strRepeat.equalsIgnoreCase("No")) {
exp = strTimeMin + " " + strTime + " " + startDate[2] + " " + startDate[1] + " *";
} else if (strRepeat != null && strRepeat.equalsIgnoreCase("Daily")) {
exp = exp;
} else if (strRepeat != null && strRepeat.equalsIgnoreCase("Weekdays")) {
// System.out.println(" expression for weekdays before : " + exp);
exp = exp.replace("*", strCalDay);
// System.out.println(" expression for weekdays after : " + exp);
} else if (strRepeat != null && strRepeat.equalsIgnoreCase("Weekends")) {
// System.out.println(" expression for weekend before : " + exp);
exp = exp.replace("*", "6,7");
// System.out.println(" expression for weekend after : " + exp);
}
System.out.println(" cron expression ::: " + exp);

Beginner: concat a string from different primitives

Apologies, as I'm sure this is a stupid question, but...
Please could anyone explain to me why this:
public class java {
public static void main(String[] args) {
byte zero = 0;
short one = 1;
int three = 3;
long one2 = 1;
float onepointnought = 1.0f;
double onedotnone = 1.0;
char letterh = 'H';
char letterw = 'w';
char letterr = 'r';
char letterd = 'd';
boolean bool = true;
String output = letterh + three + one + one2 + zero + " " + letterw + zero + letterr + one + letterd + " " + (onepointnought+onedotnone) + " " + bool;
System.out.println(output);
} }
Is outputting:
77 w0r1d 2.0 true
I'm expecting it to say "H3ll0 w0r1d 2.0 true"
It's from the interactive online java tutorials over at http://www.learnjavaonline.org/
Thanks!
Neil.
In this sentence
String output = letterh + three + one + one2 + zero + " " + letterw + zero + letterr + one + letterd + " " + (onepointnought+onedotnone) + " " + bool;
the letterh contains 'H' whose ASCII value is 72 & the addition of three + one + one2 + zero is 5 because these are non-string variables, so it is displaying (72 + 5)77 in the result,
you must convert three , one , one2 , zero to sting variable

entering different date time formats

I'm reading from an oracle database a date in this format: dd/mm/yyyy HH24:mi:ss.
when i write a query i have to write the whole date with seconds and minutes.
i need a way to write a query without giving this HH24:mi:ss.
how can i enter a date like 4/7/2011 and get it in this format dd/mm/yyyy HH24:mi:ss
this is the query:
q = "select * from MPOS t where t.TRANSACID='" + n +
"'and t.REPORTDATE between to_date('" + st + "', 'dd/mm/yyyy HH24:mi:ss')"
+ " and to_date('" + end + "', 'dd/mm/yyyy HH24:mi:ss')";
where st and end are DateTime
try use ToShortDateString():
q = "select * from MPOS t where t.TRANSACID='" + n +
"'and t.REPORTDATE between to_date('" + st.ToShortDateString() + "', 'dd/mm/yyyy')" +
" and to_date('" + end.ToShortDateString() + "', 'dd/mm/yyyy')";
I think you will also have to change the order of dd and mm so it would be 'mm/dd/yyyy'

Resources