I am doing a datediff in an access field that I now need to also remove a 50 minute lunch break from. Everything I have tried has created crazy numbers. This is the function that works correctly without removing the lunch break:
=(DateDiff("n",[DispatchTime],[ReturnTime]))\60 & Format((DateDiff("n",[DispatchTime],[ReturnTime])) Mod 60,"\:00")
Then I try:
=(DateDiff("n",[DispatchTime],[ReturnTime]-.5))\60 & Format((DateDiff("n",[DispatchTime],[ReturnTime]-.5)) Mod 60,"\:00")
How can I do this? and still show in h:mm format?
The following should suffice:
=Format(DateAdd("n",-50,[ReturnTime])-[DispatchTime],"h:nn")
Return Time - .5 will remove 1/2 a day e.g.12 hours.
DateAdd ("n",-50, [YourDatefield]) will subtract 50 minutes.
Related
I don't see any related questions to conditional formatting regarding a time value. I have a report that needs to highlight any times greater than 06:30. I had the field set to Medium Time (06:30 AM) but the AM/PM may be an issue so now I am trying simply short time.
I have tried every combination or Left, Right, Hour, Minute - the real issue is simply the 30 minutes between 06:00 and 06:30 that is the issue. I can do a simple "Expression is Left([Time],2)>5 to get anything above 06:00, but I don't want anything from 06:00 to 06:30 highlighted.
Is the solution to this converting the time to a number first, and then applying the conditional format?
Never use strings for handling date and time. No exceptions.
You have dedicated functions for this, like:
DateDiff("n", #06:30:00#, [TimeField]) > 0
or even:
DateDiff("n", TimeSerial(6, 30, 0), [TimeField]) > 0
If a date value is included, strip that with TimeValue:
DateDiff("n", #06:30:00#, TimeValue([TimeField])) > 0
I need time worked to do some other calculations and the times are all coming back negative if they worked an over night. Here is my formula that I am using to calculate time worked. (([EndTime]-[StartTime])*24*60) As long as they complete their shift in the same day, the calculation works fine but, if they work 6am to 6 pm, I get a total shift time of -720. All of my calculations are in minutes by the way. Does anyone know how to make the negative time show correctly? Thanks!
You can use this expression:
Minutes = (1 + EndTime - StartTime) * 24 * 60 Mod 24 * 60
For your example, values would be:
Minutes = (1 + #6:00# - #18:00#) * 24 * 60 Mod 24 * 60
This is an old trick based on the fact that the Date data type has an "undocumentated window" between but not including the numeric values 0 and -1.
Thus, the limitation is that it will only work for durations less that 24 hours.
You can use this formula:
Datediff("n", StartTime, EndTime)
Where "n" says you want the difference in time between those dates as minutes.
If you still get negative numbers after this then I suspect you are not storing the date and time together (you should be).
Basically I just need to know how much time has passed from a certain time that day till Now() this will be run on a timer throughout the day and used to determine when something should be run (this might seem odd but there is logic behind it).
The issue with the code below is that it gives me a very high negative number. I can only assume that this is caused from the TimeSerial not actually containing a date and only the time so it throws everything off.
Can anyone point me in the direction of a way to do what I want? I am certain that the answer is something super simple that I am missing but I haven't been able to find it.
DateDiff("n",Now(),TimeSerial(07,0,0))
You want the number of minutes from 7 AM until now. Your DateDiff had those two swapped around and that's why you got a negative value.
The reason the magnitude of that number was so large is you were asking for the difference between 07:00 on Dec 30 1899 and today. This is what that TimeSerial expression gives you ...
? Format(TimeSerial(07,0,0), "mmm d yyyy, hh:nn:ss")
Dec 30 1899, 07:00:00
I think this is what you want instead ...
DateDiff("n", Date + #07:00#, Now)
I have a column in my report that contains text values like:
01:30
00:45
02:15
And so on. How do I get a total like this?
04:30
As a total time spent. I am trying this Expression -
= FLOOR(Sum(Cint(Left(Fields!est_pack_time.Value,2)), "DataSet1") ) & ":" & RIGHT("0" & (Sum(Cint(Right(Fields!est_pack_time.Value,2)), "DataSet1") MOD 60), 2)
This gives me something close but it is still not right. I am summing the total time across the entire dataset.
You were on the right track - your expression is just not carrying the extra hours from summing up the minutes into the total hour time.
The updated expression will be something like this:
=Right("0" & Sum(CInt(Left(Fields!est_pack_time.Value,2)), "DataSet1")
+ Floor(Sum(CInt(Right(Fields!est_pack_time.Value,2)), "DataSet1") / 60),2)
& ":" & Sum(CInt(Right(Fields!est_pack_time.Value,2)), "DataSet1") Mod 60
This is taking the total from the hours, adding the overflow from the total minutes, then concatenating the minutes to this string. It's also padding the hours with a leading zero to make sure the string is always 5 characters.
Works for me in a quick test:
Finally, it probably goes without saying that if at all possible it's best to move away from storing time durations in a text format, but of course that might not be possible in your case.
=split(TimeSpan.FromTicks(Sum(Fields!TotalHours.Value)).TotalHours,".").GetValue(0) &":"
& Format(TimeSpan.FromTicks(Sum(Fields!TotalHours.Value)).TotalMinutes mod 60,"00")
=replace( left(TimeSpan.FromTicks(Sum(Fields!TotalHours.Value)).TotalHours,3)&":"
& right(TimeSpan.FromTicks(Sum(Fields!TotalHours.Value)).TotalHours,3)*60,".","")
I am trying to write a query where I can eliminate a timediff of less than 2 minutes. I have tried variations on the following which returns no results
timediff(sessions.producer_on,sessions.producer_off)>'00:02:00'
the timediff without the > works fine and returns all results - I am having difficulty with the >00:02:00 condition. Can anyone help - many thanks
You need to extract the minute from the time then compare it.
minute(timediff(sessions.producer_on,sessions.producer_off)) > 2 AND
hour(timediff(sessions.producer_on,sessions.producer_off)) = 0
Also it may be necessary to make sure that the hour is 0 since only when the hour is zero does the minute actually matter.
This is probably the "old way" but it eliminates the need to check hours, days, etc.
UNIX_TIMESTAMP(fieldOne) - UNIX_TIMESTAMP(fieldTwo) < 120
You can also use NOW() in place of a field name.
Change it to
timediff(sessions.producer_on,sessions.producer_off) > TIME('00:02:00')
and it should work.
SELECT * FROM e_email_otp WHERE TIMEDIFF('2019-01-11 10-46-19',`2019-01-11 10-45-19`) <'00:02:00.000000'