is node-cron job intervals inclusive of both? - node-cron

I want to run 2 cron jobs.
0-7 at 1 hour interval (i.e. 0,1,2,3,4,5,6,7)
7-0 at 15 min difference (7:00 should not be included here as it is include in earlier interval and 00:00 shouldn't be here also since it is included earlier)
Now, what I have done is this:
'0 0 0-7 * * *'
and for 7-0 job
'0 */15 7-0 * * *'
The problem as you may have noticed is that at 00:00 both cronjobs will be implemented, which I don't want.
One way can be to start the job at 7:15 - 23:30 for 15 minutes but I don't know how to do it.
Any help would be appreciated.
Thanks

Related

Weird time calculation in mysql when adding / subtracting months

I'm trying to perform some time calculations (timestampadd, timestampdiff) on a query but I'm stuck with an unexpected behavior.
I executed in mysql this query:
select timestampdiff(MONTH, timestampadd(MONTH, 1, '2017-01-30'),'2017-01-30')
Using logic is adding to 2017-01-30 one month, then it requests the difference in months between this date and again 2017-01-30.
I'm expecting the result to be trivial and equal to 1 but instead the previous query evaluates to 0.
This screws my calculations.
Why is that?
This is straight forward,
you are adding 1 month in january 30 which will be feb 28 as in 2017
now the difference between jan30 and feb28 is only 29 days which is less than a month value. ( 30 days )
Therefore its 0
for accuracy, you need to handle february with care .

Calculate time difference from MySQL time

I am using the following call in my query to calculate the amount of time between now and a timestamp:
(NOW() - bu.banusr_expire)
bu.banusr_expire is a TIMESTAMP field.
I'm a little confused about the number it is returning.
ex; it returns -928 when there is about a 9.5 minute difference.
This makes me think that -928 = -9mins and 28 seconds(or 15 seconds. This set of digits seems to go from 0-99), but that seems completely wrong.
My question is, how can this value be converted to minutes?
If you can be confident that the difference between the two times will always be less than 839 hours, then you can use TIMEDIFF().
(UNIX_TIMESTAMP() - UNIX_TIMESTAMP(bu.banusr_expire)) / 60
should give you the number of minutes ;)
use unix timestamp
select UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(fieldname)
this will give you the diff in seconds you will have to divide by 60 for minutes

MySQL - Age in minutes

This is a pretty simple homework problem that I've been stuck on for a while. Can someone show me how to go about solving this?
A baby is born on March 1 2012 12:00:00. How old will he be in minutes on July 4th 2013 13:30:00?
Use this query
SELECT TIMESTAMPDIFF(MINUTE, '2012-03-01', '2013-07-04')
Use DATEDIFF() to count the difference in days, than multiply it by 24 * 60 * 60 (number of seconds in a day)..

Converting Decimal Value to Hours and Minutes and also to Hours

I store time like this
1.30 == 1 Hour 30 minutes
2.70 == 3 Hours 10 minutes
I need to convert 2.70 to 3 Hours 10 minutes
And also 3 hrs 10 minutes in to Hours
How to solve this in SQL server 2008
Please help me
If 1.30 = 90 minutes then 1 = 69.23076923076923 minutes
Then 2.70 to minutes ->
2.70 * 69.23076923076923 = 186.9230769230769 (minutes)
186.9230769230769 / 60 (minutes in an hour) = 3.115384615384615
From 3.115384615384615 you take the integer part as hour (3) and the decimal as the minutes (1153.....)
I don't know exactly how you came up with the formula but it seems that the conversion factor is going to give you decimal places that you are going to have to take into account (round or eliminate them)
Use the same procedure but INVERSED to get from 3 hours 10 minutes to 2.70
BUT like it was mentioned before, I don't understand why you are using SQL to do this formula calculation.

Interval from difference of two times in MySQL

I have a MySQL query that uses two different timestamps that can be perceived as an interval of time. I need to implement an extra 25-30% of the difference. For example, if the difference between the times is 30 minutes, I need to request an additional 5 minutes before and 5 minutes after.. Is there a way to not only get the difference between the two time stamps, but then calculate this 'percentage' of time to acquire the appropriate interval, all within one statement?
Something like the following, where x is the calculated value.
..
DATE_FORMAT(timestamp1 - INTERVAL x MINUTE,'%m/%d/%Y %r') AS 'Start',
DATE_FORMAT(timestamp2 + INTERVAL x MINUTE,'%m/%d/%Y %r') AS 'End',
..
You have a start timestamp and an end timestamp in the database. You want to add an additional percentage of time to these values, based on the time span between them. In other words, you can't add or subtract any amount of time without knowing the difference between the two.
So, first you must figure out the time span. I'm going to use minutes as the unit, but use whatever works best for your needs:
SELECT
#new_span := TIMESTAMPDIFF(MINUTE, timestamp1, timestamp2) * 1.25 new_span,
DATE_SUB(timestamp1, INTERVAL (#new_span*60)/2 SECOND) AS new_start,
DATE_ADD(timestamp2, INTERVAL (#new_span*60)/2 SECOND) AS new_end,
TIMESTAMPDIFF(MINUTE, timestamp1, timestamp2) old_span,
timestamp1 AS previous_start,
timestamp2 AS previous_end
FROM table;
So this query stores the difference between the two times plus 25% as a variable named new_span. The new_start and new_end fields use the variable (converted to seconds and divided in half) to modify the original start/end times. I'm also selecting old_span and the original start/end times, for comparison.
Here is sample output:
new_span new_start new_end old_span previous_start previous_end
1.25 2011-08-11 15:53:22 2011-08-11 15:55:38 1 2011-08-11 15:54:00 2011-08-11 15:55:00
1350.00 2011-08-09 00:45:00 2011-08-10 17:15:00 1080 2011-08-09 12:00:00 2011-08-10 06:00:00