VBScript echo every 30 seconds - datetime

The following code writes to the screen every iteration. Based on my understanding of the DateDiff documentation, it should only write every 30 seconds. What did I do wrong?
lasttime = Now
Do While Not data.eof
'looping through database records
if DateDiff(s,lasttime,Now) >= 30 Then
lasttime = Now
WScript.Echo "It's been 30 seconds..."
End if
Loop

Change this line:
if DateDiff(s,lasttime,Now) >= 30 Then
To this (note the quotes around "s")
if DateDiff("s",lasttime,Now) >= 30 Then

Related

how to write this if else statement in R?

Does anyone know how to write an if else statement in R where if the departure delay is more than 15 minutes then the airline has to pay $75 for every minute delayed and if the departure delay is less than 15 minutes then there is no charge?
This is what I wrote but its throwing an error
mutate(`Departure Delay charges`= if_else(`departure_delay`>= '16'|`DEP_DELAY`<='15',75*`departure_delay`, "0" ))
If you need > 15 mins, then the second dep_delay is not necessary. If true it will multiply departure_delay by 75, it it is FALSE - it will stay 0.
DepartureDelayCharges = ifelse(departure_delay >= 16, 75*departure_delay, 0)

MomentJS comparing Unix time with minutes and get difference

I need to find if currentDate time (unix) and lastFetchedTime(unix) is greater than 30 minutes in moment.js.
How can compare the subtracted value from 30 minutes in moment?
lastFetchedTime(unix) is equivalent to the previous Date.now()..
const now = moment(Date.now());
const lastFetched = 1598578706;
const checkTime = now.diff(lastFetched, 'minutes') > 30 ;
You can use momentJS duration function to get the difference between two times which are in unix format.
Firstly, you need to convert the unix format to human readable time and then get the difference of current time and lastFetched time using asMinutes function of duration
If the difference is greater then 30 then do something else or do something else.
Live Demo:
const now = moment().unix()
const lastFetched = 1598597404;
const duration = moment.duration(moment.unix(now).diff(moment.unix(lastFetched)));
const getMinutes = duration.asMinutes();
if (getMinutes > 30) {
console.log('Minutes are GREATER then 30 minutes - from now')
} else {
console.log('Minutes are LESS then 30 minutes - from now')
}
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.js"></script>

How do I convert milliseconds to dd:hh:mm using moment.js?

I'm trying to get the days, hours and minutes of 9000000 milliseconds, but moment.js is returning 0 days. I'm using Format plugin for the Moment Duration object. https://github.com/jsmreese/moment-duration-format
moment.duration(9000000, "milliseconds").format("dd:hh:mm");
returns "02:30"
How did I get 9000000?
var ms = moment.duration({
days: 1,
hours: 2,
minutes: 30,
})
console.log(ms._milliseconds);
// 9000000
Sounds like humanizeduration is what you are looking for:
humanizeDuration(97320000) // '1 day, 3 hours, 2 minutes'
Here is the github link:
https://github.com/EvanHahn/HumanizeDuration.js
1000 x 60 x 60 x 24 = 86'400'000 milliseconds.
Of course 9 mil is 0 days.
9'000'000 / (1000 x 60 x 60) = 2.5h = 2 hours 30 min
I hope I know how to use calculator
Check this place

correct sum of hours in access

I have two columns in an access 2010 database with some calculated field:
time_from time_until calculated_field(time_until-time_from)
10:45 15:00 4:15
13:15 16:00 2:45
11:10 16:00 4:50
08:00 15:00 7:00
08:00 23:00 15:00
Now so far, it is good: calculated field did its job to tell me total hours and mins...
now, I need a sum of a calculated field....
I put in an expression builder: =Sum([time_until]-[time_from])
I guess total sum should give me 33:50... but it gives me some 9:50. why is this happening? Is there a way to fix this?
update:
when I put like this:
=Format(Sum([vrijeme_do]-[vrijeme_od])*24)
I get a decimal point number... which I suppose is correct....
for example, 25hrs and 30mins is shown as 25,5
but, how do I format this 25,5 to look like 25:30?
As #Arvo mentioned in his comment, this is a formatting problem. Your expected result for the sum of calculated_field is 33:50. However that sum is a Date/Time value, and since the number of hours is greater than 24, the day portion of the Date/Time is advanced by 1 and the remainder 9:50 is displayed as the time. Apparently your total is formatted to display only the time portion; the day portion is not displayed.
But the actual Date/Time value for the sum of calculated_field is #12/31/1899 09:50#. You can use a custom function to display that value in your desired format:
? duration_hhnn(#12/31/1899 09:50#)
33:50
This is the function:
Public Function duration_hhnn(ByVal pInput As Date) As String
Dim lngDays As Long
Dim lngMinutes As Long
Dim lngHours As Long
Dim strReturn As String
lngDays = Int(pInput)
lngHours = Hour(pInput)
lngMinutes = Minute(pInput)
lngHours = lngHours + (lngDays * 24)
strReturn = lngHours & ":" & Format(lngMinutes, "00")
duration_hhnn = strReturn
End Function
Note the function returns a string value so you can't do further date arithmetic on it directly.
Similar to the answer from #HansUp, it can be done without VBA code like so
Format(24 * Int(SUM(elapsed_time)) + Hour(SUM(elapsed_time)), "0") & ":" & Format(SUM(elapsed_time), "Nn")
I guess you are trying to show the total in a text box? the correct expression would be =SUM([calculated_field_name]).

displaying current minute of a soccer match

I could not figure out the logic I would need to display a current minute of a soccer match. I have three fields in the database.
DateFirstStarted
DateSecondStarted
DateFullEnded
I should enter DateFirstStarted when the game starts and on the website. i.e. game starts at 7:05pm, on 7:25pm it should display '20 on the website. However, it should stop on the 45th minute. Then, I enter DateSecondStarted when the second half starts and should count from 46 to 90 and freeze there. Do I make sense? How can I do it? Is there a better way to do this?
Something not too complicated should do it. I will update start date of first half and start date of second half myself.
Here is how I tried it. I dont get an error but its not working. Any suggestion appreciated.
DateFirstStarted = objLiveCommentary("DateFirstStarted")
DateFirstEnded = DateAdd("n", 45, DateFirstStarted)
DateSecondStarted = objLiveCommentary("DateSecondStarted")
DateSecondEnded = DateAdd("n", 45, DateSecondStarted)
If DateFirstStarted => NOW() => DateFirstEnded Then
Response.Write "first half"
ElseIf DateSecondStarted => NOW() => DateSecondEnded Then
Response.Write "second half"
End If
Have a look at the DateDiff function?
You pass it two datetimes and it will give you the total amount of mins / seconds / hours etc between the two values.
http://www.w3schools.com/vbScript/func_datediff.asp
E.g.
If DateDiff("n",StartOfMatch,Now()) < 45 Then
FirstHalf = True
Elseif DateDiff("n",StartOfMatch,Now()) >= 45 Then
SecondHalf = True
Else
MatchEnded = True
End If
Hope this helps you?
C

Resources