Set a value to Duration in MSProject - vba

I can't seem to assign a value to Duration field in MSProject by using VBA.
Probably has something to do with types?
Tsk.Duration = (rate1)
--while rate 1 is defined as long and equals 14
the value that appears is 0.03 (in days). Why not 14 days???
Tsk.Duration is Variant/Long
Thanks in advance,
Sivan

The Duration of a task is stored in minutes, not days. To set a duration of 14 days use:
Tsk.Duration = 14 * 8 * 60.

Related

convert duration to seconds

Im beginner using sql. Im creating new column
x1 = date_order - date_Delivery
to mesure the duration of waiting time of clients. My column X1: contains for example (00:10:24.949131, 01:00:01, 2 days 00:40:45). I want to convert this duration to seconds , in this case the second values will be 3601.
Can anyone help me please?
You can do:
extract(epoch from date_order - date_Delivery) / 60
This expression converts the interval to a number of seconds, that you can then divide by 60 to get the corresponding number of minutes.

Find recent date of cyclical event

Let's suppose that some event started on 1st January 2000 and is repeated every 36 hours and 45 minutes.
At this moment at my place it is 4th April 2018 18:30.
How could I calculate in SQL
date and time of last recent happening of my event
date and time of next future happening of my event ?
My first idea was adding my period in a loop to a start date until required date is reached but that would be very ineffective with longer time spans, I believe
Thank you for any help.
We could parameterize an sql statement with the results of this integer math...
int now = current time in minutes after 1 Jan, 2000
int period = 36 * 60 + 45
int eventsBeforeNow = now / period /* where '/' is a truncating, integer divide */
int lastEventTime = eventsBeforeNow * period
int nextEventTime = lastEventTime + period
Okay, I found the answer myself. Seems to work
declare #minutes int,#n int,#period int
SET #period=36*60+45
select #minutes=datediff(minute,'2000-01-01 00:00:00','2018-04-04 18:30:00')
set #n=#minutes/#period
select DATEADD(minute,#n*#period,'2000-01-01 00:00:00')
select DATEADD(minute,(#n+1)*#period,'2000-01-01 00:00:00')
Recent time of my example event is 2018-04-04 14:15:00.000
Next time of my example event is 2018-04-06 03:00:00.000

SQL Statement - condition within a condition?

I have a table where each record contains the time, represented by
an hour column (int) and a minute column (int).For example:
**records |hours| mins**
record1 | 15 | 30
record2 | 12 | 25
I want to write a statement where only the records ahead of the current time will be displayed. So far, I have:
SELECT...
WHERE hours >= hour(current_time)
AND
mins >= minute(current_time)
AND...
But this doesn't work because it needs both the hours and mins to be greater than the current hours and minutes. How do I write to that so that if the hours are the same, then the minutes are compared?
Do something like this:
WHERE hours >= hour(current_time)
OR (hours = hour(current_time) AND mins >= minute(currentime))
Something like
Where hours * 60 + mins > hours(currentTime) * 60 + minute(currentTime)

How can I convert and round-up seconds to the next full minute?

I have a time usage amount in an Oracle table stored as a number of seconds:
5
10
100
500
How can I convert the number of seconds to the number of minutes, rounded up to the next closest minute? For the seconds values above I want to get:
1
1
2
9
Assuming you are actually using Oracle, you can use the CEIL function to 'round up' the fractional number of minutes you get by dividing by 60 to the next integer.
ceil(your_column/60)
So with some sample values:
select seconds, ceil(seconds/60) as minutes
from your_table
order by seconds;
SECONDS MINUTES
---------- ----------
5 1
10 1
100 2
500 9
1800 30
You're trying to divide it by 60 and "trunc up". Unfortunately there isn't a built-in function that does exactly that, but trunc can still be used:
SELECT CASE TRUNC(myseconds/60) WHEN myseconds/60 THEN myseconds/60
ELSE TRUNC(myseconds/60) + 1
END
FROM my_table
EDIT:
Or in a more elegant form with a subquery:
SELECT CASE TRUNC(myminutes) WHEN myminutes THEN myminutes
ELSE TRUNC(myminutes) + 1
END
FROM (SELECT myseconds/60 AS myminutes
FROM myable)

Case statement for calculating hours

I have the following formula to convert the duration into hours. I want to do case where any duration which is 15 min or more Is considered as an hour. for instance 1 hour 15 min will be calculated as 2 hrs, 2 hrs 15 min will be calculated as 3 hrs and so on. if it is less than 15 min after an hour than it will be the hour. eg 1 hr 5 min will be considered 1 hour.
((Case T0.DurType when 'M' then (T0.Duration/100)/.60 when 'D' then (T0.Duration*8) Else T0.Duration End)) as 'Duration'
Are you doing this in SQL or as a formula field in Crystal?
Is case syntax required for some reason, or is that simply the approach you initially chose?
What unit of time does each increment of Duration represent, 1 second, 1 minute?
Assuming the following:
this is in sql
case syntax is not required
each increment of Duration is 1 minute
Then here is your correct formula, using ceiling rather than case:
ceiling(T0.Duration/60) as "Duration"
That will increment any partial decimal value to the next highest integer, e.g., 75 minutes / 60 = 1.25 hours, and ceiling will increment to 2. 180 minutes / 60 = 3.00 hours and ceiling will output 3.
EDIT:
I'm not sure what you mean by achieving it in sql & crystal... if you calculate it in sql, it's passed to Crystal and won't need any further transformation. Either way, here's both solutions:
Crystal: Assumes minutes are used. the "\" operator is integer division, so the decimal is dropped. A simple if/then/else iif is used to add either 1 or zero if the remainder minutes are 15 or more:
MINUTES \ 60 + IIF (MINUTES mod 60 >= 15,1 , 0)
In SQL (MySQL syntax, MSSQL/TSQL may vary) achieves the same as follows:
floor(MINUTES / 60) + IF( (MINUTES % 60) >= 15,1 , 0)