Basic DateTime Algebra - vb.net

How do i go about writing some basic algebra math in vb.net?
Example:
I need to schedule a process to run 60 days before start date of an object.
When my process runs I do:
Now(UTC) - StarDate(UTC) = days diff
If days diff less than 60, i run my process immediately.
If its over 60 days, i need to schedule my process to run again in 60 days.
So this leaves me with:
X - [daysDiff] = 60
I know how to solve this on paper but not in vb.net code.
Example:
X - 107 = 60
add 107 to each side, i have my # of days to add (107)
How do i accomplish this in VB.net?

If you want to know when to run it: if it's over 60 days, then subtract 60 from that value, that will tell you when when to check again.... so if you do the initial check and it comes back 61 days different, it's over 60, so you subtract 60, leaving 1. So now you know you need to schedule it in 1 day. If you do the initial check and it comes out 107, you subtract 60 and the result is 47... so you know in 47 days, you need to run it again as that will be 60 days out. It's two simple steps.

Related

How to make a duration picker react native

I am trying to build a duration picker:
it would look like a simple ios time picker, but it would start with 0 minutes and 0 seconds and go up to 23 hours and 59 minutes.
I tried using normal DateTimePickers (react native date picker), and using the 24 hours format, and that would work. The problem is that ios doesn't support the 24 hours format.
PS: the 12 hours format, as you can see from the image, starts from 1 hour and 0 minutes, so that would not be good if someone would want to take 20 minutes, for example.
It would look something like this, but in 24 hours format, starting from 0 hours and 0 minutes, and going till 23 and 59 minutes.
I found a way to implement this:
I used another library (react-native-modal-datetime-picker) and, as said in the docs, you can't set a 24 hours format on ios, but what you can do is setting
locale="en_GB"
Using this you can now achieve this look:
As you can see you will be able to choose even times with 0 hours.
To get the minutes, on the Date object you will get as a prop of onConfirm, do this:
const minutes = date.getMinutes() + date.getHours() * 60;
console.log(minutes);
Finally, if you want your DurationPicker to start at 0 0, set the prop date to a date with 0 hours and 0 minutes.
At the end it is going to look something like this:
<DateTimePicker
mode='time'
date={new Date(new Date().setHours(0, 0, 0, 0))}
locale='en_GB'
{...props}
/>

Round to sequencial values with a variable number of hours - Kotlin

I need to solve this problem that I've been trying for a long time and nothing to achieve.
In my app, the user clicks a button that advances through a calendar day by day, but, I need to return in this method, the exact sequence of a certain value that is given in a certain number of n days and n hours.
I explain: the calendar is stopped on a day whose value is: 22 days and 3 hours (1), the user clicks to advance one day and the new value for that day is: 22 days and 10 hours (2) which are converted into hours to return a sequential integer each day ahead.
Thus, in the formula ((day * 24) + hours) / 24 we have:
((22*24)+ 3)/24 = 22,125(1)
((22*24)+21)/24 = 22,416(2)
rounding these values, we have the value for both days, it is both 22, but the value for the next day would have to be 23.
Look:
For the current day the calculated value is 22
for the next day, it is also 22, but must be 23 (sequencial value).
How do I solve this in kotlin?
Can anyone here help me?
Thanks in advance
[EDIT]
Maybe I can better explain the problem with this figure

Updating dates with random time

I have a datetime column, all of them at 12:00 am. Is there a way to update them with random hours, minutes to nearest 1/2 hour while keeping the same date(day) value?
Update Activities set ActivityDate = ....
Here's one option using dateadd:
update Activities
set ActivityDate = DateAdd(minute,
30 * (abs(checksum(NewId())) % 47), ActivityDate);
SQL Fiddle Demo
And here's a good post about generating random numbers. Using that, multiple by 30 minutes to get to the nearest half hour.
Note, this uses % 47 since there are 1440 minutes in a day -- that divides into 48 potential half hour segments in that same day.

How to register every day local notification at certain time?

How can I realize everyday local notifications in my app? So at first run I need to register first local notification at 14:00 and then everyday at 14:00 notification should appear.
User can change this time in app's settings.
How to do this mechanism?
You need to handle the notifcations on your end, but to make a timer that countsdown to a certain time every day, you would need to do something like this:
local targetDate = os.time{ year=2014, month=11, day=8, hour=0, sec=0 } -- Get the date that you want to count down to, in seconds
local text = false
local function enterFrame(event)
if text then text:removeSelf() end -- Everyframe, remove the old text object
local timeRemaining = (targetDate-os.time()) -- Take the difference between the target time and the current time
local days = timeRemaining / 86400 -- get the number of days left by dividing the remaining seconds by the number of seconds in a day
local hours = days%1 * 24 -- get the number of hours left by multiplying the remainder by the number hours in a day
local minutes = hours%1 * 60 -- get the number of minutes by multiplying the remainder by the number of minutes in an hour
local seconds = math.floor( minutes%1 * 60 + 0.5) -- multiply the remainder one more time by the number of seconds in a minute, and round to the nearest second.
-- make a new text object to display all the info
text = display.newText( "Will be available in "..math.floor(days).." days "..math.floor(hours).." hrs "..math.floor(minutes).." mins "..seconds.." secs ", 25, 140)
end
Runtime:addEventListener( "enterFrame", enterFrame )
You can repurpose your code to work with your project, but you need to use OS time and do certain calculations to each variable in order to get the time. Good luck.

Sum of hours and minutes when minutes exceeding 60 minute [duplicate]

This question already has an answer here:
Sum of hour and minutes in SQL Server 2008
(1 answer)
Closed 8 years ago.
I have one query,but it not giving correct answer.I want to display like this 5 Hour 58 minutes + 7 Hour 58 minutes=13 hour 56 minutes (the answer should be 13.56),but this below query giving output 13.6 .
Please reply me with any other solution. (Effort1 is 5 Hour column, Effort1Minutes is 58 minute column and same Effort2 is 7 Hour column, Effort2Minutes is 58 minute column .
select SUM(Effort1 + Effort2) + SUM(Effort1Minutes + Effort2Minutes) / 60 + CONVERT(decimal(18,2), (SUM(Effort1Minutes + Effort2Minutes) % 60) / 100.00)
from TimesheetDetails
When you have an hammer, every problem looks like a nail. This is a common pitfall, which basically means "use the right tool for each given problem".
Why are you using such a convoluted query to calculate a sum of times?
Why don't you have two TIME columns, which you can later add using ADDDATE(d1, d2)
Why don't you use a TIME INTERVAL datatype, as defined in the SQL 99 Standard?
Why don't you return the result in minutes, and leave the application to convert it into the format of your choosing?
Why don't you return separately the hours and the minutes, and once again leave the application to handle the extra hour that may arise from the sum of the minutes?
As you can see, there are plenty of other solutions that solve your issue from the root, while also granting you a better database design altogether. Please consider them, expecially the number one.