Good day,
Disclaimer: I am very new to development.
I am developing an app and the user needs to enter a start time and end time. I then want to do a calculation to get the time taken. Below is the code I am using but it returns "an empty string".
dtiStartTime = new sap.m.DateTimeInput({
id : "StartTime", placeholder:"Select Start Time", type:"Time",width:"100px"
});
dtitotalTime = new sap.m.DateTimeInput({type:"Time",value:""});
dtiStopTime = new sap.m.DateTimeInput({
id : "StopTime", placeholder:"Select Stop Time", type:"Time",width:"100px",
change: [function(oEvent){totalTime.setValue(dtiStopTime.getValue() - dtiStartTime.getValue())}]
});
"getValue()" of DateTimeInput returns a javascript Date() object.
If you call "getTime()" of the Date object you get the time in milliseconds and can subtract them from each other. Afterwards you need to transform them into a value that you need (minutes/hours)...
var startDate = dtiStartTime.getValue();
var stopDate = dtiStopTime.getValue();
var differenceInMilliseconds = stopDate.getTime() - startDate.getTime();
Here is an example how to get the difference in seconds:
var start = this.byId('dateTimeStart').getDateValue();
var ende = this.byId('dateTimeEnde').getDateValue();
var diffInSeconds = (ende.getTime() - start.getTime())/1000;
Related
I am trying to get my power bi data from my HRIS platform to calculate hours worked - hours on lunch, to get a total of hours worked in a day.
I have tried grouping, pivots, formulas, and because my HRIS platform send the "check-in" time at the start of a shift and the "check-in" time when they clock back in from lunch, as the same "check-in" classification, I cannot associate it with one or the other, it picks the most recent one, if I say return "check-in" (My data set is intraday and updates every hour so I can get all Clock events for the current day)
I have included an example of what my data looks like right from the HRIS into Power Bi
Sample Data Set
Full Data Sheet Columns
Formula's Used in Order:
Check In =
IF(AND(Merge1[Current Day]=Merge1[Day of the
Week],Merge1[Clock_Event_Type]="Check-in"),
Merge1[Clock_Event_Time_-_No_Time_Zone])
Check Out (Lunch) =
IF(Merge1[Day of the Week]= Merge1[Current Day],
IF(Merge1[Clock_Event_Type]= "Check-out
(meal)",Merge1[Clock_Event_Time_-_No_Time_Zone],BLANK()))
Check in (Lunch) = IF(Merge1[Current Day]=Merge1[Day of the
Week],
VAR checkin = Merge1[Check In]
VAR outlunch = Merge1[Check Out (Lunch)]
VAR timeinfromlunch = IF(checkin>outlunch,checkin)
return timeinfromlunch)
Check Out = IF(Merge1[Day of the Week]= Merge1[Current Day],
IF(Merge1[Clock_Event_Type] = "Check-out",
Merge1[Clock_Event_Time_-_No_Time_Zone]),BLANK())
Current Time = IF(AND(Merge1[Current Day]=Merge1[Day of the
Week],Merge1[Clock_Event_Type]="Check-in"),
NOW()
)
CPH Calc (Intraday Shift) = IF(Merge1[Current Time]<Merge1[Shift
End Today],Merge1[Current Time],Merge1[Check Out])
Hours Worked =
IF(AND(Merge1[Current Day]=Merge1[Day of the
Week],Merge1[Clock_Event_Type]="Check-in"),
VAR totalsecondsinbreak = DATEDIFF(Merge1[Check Out
(Lunch)],Merge1[Check in (Lunch)],SECOND)
VAR total_secondsworking = DATEDIFF(Merge1[Check In],Merge1[CPH
Calc (Intraday Shift)],SECOND)
VAR totalseconds = total_secondsworking-totalsecondsinbreak
VAR DAXHours = (totalseconds/60)/60
RETURN IF(Merge1[Clock_Event_Time_-
_No_Time_Zone]=0,BLANK(),DAXHours))
Shift Start Today = IF(Merge1[Current Day]=Merge1[Day of the
Week],TODAY() + Merge1[Start Shift])
Shift End Today = IF(Merge1[Current Day]=Merge1[Day of the
Week],TODAY() + Merge1[End Shift])
On Queue (Milliseconds) = IF(AND(Merge1[Current Day]=Merge1[Day
of the Week],Merge1[Clock_Event_Type]="Check-in"),
VAR onqueueseconds = RELATED('Table (2)'[On Queue])
VAR milliseconds = onqueueseconds
VAR total_second = milliseconds/1000
VAR minutes = total_second/60
VAR hours_decimal = minutes/60
VAR hours = INT(hours_decimal)
return onqueueseconds)
Utilization =
IF(AND(Merge1[Current Day]=Merge1[Day of the
Week],Merge1[Clock_Event_Type]="Check-in"),
VAR productivetime = Merge1[Hours Productive Time]
VAR workedtime = Merge1[Hours Worked]
VAR Ult = IFERROR(productivetime/workedtime,BLANK())
return Ult
)
Hours Productive Time =
IF(AND(Merge1[Current Day]=Merge1[Day of the
Week],Merge1[Clock_Event_Type]="Check-in"),
VAR milliseconds = Merge1[On Queue (Milliseconds)]
VAR total_second = milliseconds/1000
//VAR minutes = total_second/60
//VAR hours_decimal = minutes/60
//VAR hours = INT(hours_decimal)
VAR DAXHours = (total_second/60)/60
return DAXHours+.5)
My current project need to customisely showing some extra information base on calculations of the dates that has been selected. I have writen a function, and I can't find the AJAX code that the booking system returns the data and calculations base on the valid date to trigger my function.
My function is easy:
function calculate_date_duration() {
var year_1 = document.querySelector('.selection-start-date').getAttribute('data-year');
var month_1 = document.querySelector('.selection-start-date').getAttribute('data-month');
var date_1 = document.querySelector('.selection-start-date a').textContent;
var year_2 = document.querySelector('.selection-end-date').getAttribute('data-year');
var month_2 = document.querySelector('.selection-end-date').getAttribute('data-month');
var date_2 = document.querySelector('.selection-end-date a').textContent;
var day_1 = new Date(year_1, month_1, date_1);
var day_2 = new Date(year_2, month_2, date_2);
console.log(day_1);
console.log(day_2);
var day_selected = day_2.getTime() - day_1.getTime();
var date_duration = parseInt(day_selected / (1000 * 60 * 60 * 24)) +1;
console.log(date_duration);
var display_pane = document.querySelector('.wc-bookings-booking-cost');
display_pane.innerHTML = display_pane.innerHTML + '<br>Total booking cost:<strong><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>' + (date_duration*120) + '</bdi></span></strong>';}
The date select duration ajax is in wp-content/plugins/woocommerce-bookings/dist/frontend.js, search success, the last one in this file is the codes after validating the selected duration.
ccs.each do |cd|
relative_model = main_model.relative_model.where(start_date: XYZ, end_date: XYZ).first_or_initialize
relative_model.capacity = cd['capacity'].to_f
relative_model.save!
end
As per above code, first_or_initialize is not working for relative model and creating new record each time.
Here is the query run at background for both inr:
SELECT `capacity_commitments`.* FROM `capacity_commitments` WHERE `capacity_commitments`.`participants_subscription_id` = 1 AND `capacity_commitments`.`start_date` = '2016-11-16' AND `capacity_commitments`.`end_date` = '2016-11-21'
SELECT `capacity_commitments`.* FROM `capacity_commitments` WHERE `capacity_commitments`.`participants_subscription_id` = 1 AND `capacity_commitments`.`start_date` = '2016-11-16' AND `capacity_commitments`.`end_date` = '2016-11-21'
NEED INITIAL HELP OR POINT OUT WHAT IS WRONG IN ABOVE CODE?
Try to use find_or_initialize_by method
relative_model = main_model.relative_model.find_or_initialize_by(start_date: XYZ, end_date: XYZ)
i have a time format like this:
string s = DateTime.Now.ToString();
which gives me output like
11/29/2013 6:26:13PM
Now how can i convert this output into millisecond in windowsPhone???
Updated:
First i want to save the current time when the user launch my app. after that whenever the user launch my app again then i also get the time and compare the current launching time with previously stored time and check whether the time difference becomes "one day" or not.
For this comparison i need to covert 11/29/2013 6:26:13PM this into millisecond.
Another question tell me how can i convert "6:26:13PM" only this into millisecond??
If I understood correctly just do this:
Create a date from your input:
DateTime yourInitialDateTime = DateTime.Parse("11/29/2013 6:26:13PM");
After that
TimeSpan span = DateTime.Now - yourInitialDateTime;
So in span.TotalDays you will have how many days has passed.
Edit
If you have only the time of day and want to know the millisecond of that time you must add a date and subtract it with hour 0:00:00 like this:
string dummyDate = "01/01/0001";
DateTime end = DateTime.Parse(dummyDate + " " + "6:26:13PM");
var milli = end.Subtract(new DateTime()).TotalMilliseconds;
That is it.
Try this.
var ThatDay = DateTime.Now.AddDays(-1); //This is hard coded but you have to get from where you are storing.
var Today = DateTime.Now;
var Diff = (Today - ThatDay).Milliseconds;
var FriendlyDiff = (Today - ThatDay).ToFriendlyDisplay(5);
public static class TimeSpanExtensions
{
private enum TimeSpanElement
{
Millisecond,
Second,
Minute,
Hour,
Day
}
public static string ToFriendlyDisplay(this TimeSpan timeSpan, int maxNrOfElements)
{
maxNrOfElements = Math.Max(Math.Min(maxNrOfElements, 5), 1);
var parts = new[]
{
Tuple.Create(TimeSpanElement.Day, timeSpan.Days),
Tuple.Create(TimeSpanElement.Hour, timeSpan.Hours),
Tuple.Create(TimeSpanElement.Minute, timeSpan.Minutes),
Tuple.Create(TimeSpanElement.Second, timeSpan.Seconds),
Tuple.Create(TimeSpanElement.Millisecond, timeSpan.Milliseconds)
}
.SkipWhile(i => i.Item2 <= 0)
.Take(maxNrOfElements);
return string.Join(", ", parts.Select(p => string.Format("{0} {1}{2}", p.Item2, p.Item1, p.Item2 > 1 ? "s" : string.Empty)));
}
}
am using KeywordQuery to search and.. the SortList does not affect result, it is always return first 5 results. Any suggestion? The code is bellow...
using (KeywordQuery query = new KeywordQuery(site))
{
var fedManager = new FederationManager(application);
var owner = new SearchObjectOwner(SearchObjectLevel.SPSite, site.RootWeb);
query.SourceId = fedManager.GetSourceByName("NewsRS", owner).Id;
query.QueryText = string.Format("WorkflowStatusOWSCHCS:Approved PublishedUntilDate>=\"{0}\" OR NewsNewsPublishedDate<=\"{0}\"", DateTime.Now);
query.KeywordInclusion = KeywordInclusion.AllKeywords;
query.RowLimit = 5;
query.StartRow = 1;
query.SelectProperties.Add("NewsFriendlyUrl");
query.SelectProperties.Add("NewsNewsTeaser");
query.SelectProperties.Add("NewsNewsDate");
query.SelectProperties.Add("NewsPublishedUntilDate");
query.SelectProperties.Add("NewsNewsContent");
query.SelectProperties.Add("NewsNewsPublishedDate");
query.SelectProperties.Add("NewsNewsImage");
query.SortList.Add("NewsNewsDate", SortDirection.Descending);
var searchExecutor = new SearchExecutor();
var myResults = searchExecutor.ExecuteQuery(query);
}
}
... the NewsNewsDate is marked as Sortable
query.RowLimit = 5; => You are explicitly specifying the Rowlimit to be 5. That is why it returns the first 5 results always. Change the rowlimit and set it to the number of results you need.