created table as below:
login("admin", "123456")
if(existsDatabase("dfs://compoDB")){
dropDatabase("dfs://compoDB")
}
n = 1000000
ID = rand(100, n)
dates = 2017.08.07T00:00:00.000..2017.08.08T00:00:00.000
date = rand(dates, n)
x = rand(10.0, n)
t = table(ID, date, x)
dbDate = database(, VALUE, 2017.08.07..2017.08.11)
dbID=database(, RANGE, 0 50 100)
db = database("dfs://compoDB", COMPO, [dbDate, dbID])
pt = db.createPartitionedTable(t, `pt, `date`ID)
pt.append!(t)
then executed query as below:
select * from loadTable("dfs://compoDB", "pt") where date between 2017.08.07:2017.08.08
there's an error message:
Temporal data comparison should have the same data type.
why
The type of date in where clause should be the same as that in the table. The correct query statement is as follows:
select * from loadTable("dfs://compoDB", "pt") where date between 2017.08.07T00:00:00.000:2017.08.08T23:59:59.999
My code below fails to change WALRT.
dim WALRT as datetime = latest_weight_average_request_time
dim days_latest_weight_factor = 0.5
dim WALRT_new_hour = WALRT.hour * ( 1 - days_latest_weight_factor) + last_request_time.hour * days_latest_weight_factor
WALRT.AddHours( WALRT_new_hour - WALRT.hour )
WALRT.AddHours( 4 )
AddHours returns a new DateTime with the added hours.
It doesn't work modifying directly the variable provided
WALRT = WALRT.AddHours(WALRT_new_hour - WALRT.hour).AddHours(4)
However your code it is pretty weird because you are simply adding 4 hours to the initial value and all the lines in the middle can be removed.
For example, suppose the value of the Hour property of latest_weight_average_request_time is 10.
Your code assigns the same value to WALRT so the line that calculates the value of WALRT_new_hour is like this
dim WALRT_new_hour = 10 * ( 1 - 0.5) + 10 * 0.5 ' => equals to 10
and the following line (after fixing it) is
WALRT = WALRT.AddHours(10 - 10) ' ??
so the final line just add 4 hours to the initial value
WALRT = WALRT.AddHours(4)
DateTime.AddHoursreturns an new DateTime object. So you need to write e.g.
WALRT = WALRT.AddHours(4)
I have infinite rows with with a single column assigned to define date and time in the following 'General Format' "2016.08.10 06:00:00.066". I am aware that you can't convert every single cell in this column "mm/dd/yyyy hh:mm:ss.000 AM/PM". Therefore I would a single column assigned to "mm/dd/yyyy" and another column assigned to "hh:mm:ss.000 AM/PM". The time is currently 6 hours behind as well so I would like to add 6 hours to it.
I am struggling with this as although the cells are in general or text format the time and date is being displayed as "yyyy.mm.dd hh:mm:ss.000". And can't find a way to split the two in this format
Any help is appreciated
To convert the text to a format that Excel will change to a data/time use this:
=--SUBSTITUTE(SUBSTITUTE(A1,".","/",1),".","/",1)
Then to add 6 hours you would use:
+ TIME(6,0,0)
So to get the date/time is:
=--SUBSTITUTE(SUBSTITUTE(A1,".","/",1),".","/",1) + TIME(6,0,0)
Then simply format the new cell:
mm/dd/yyyy hh:mm:ss.000 AM/PM
You can also split it into the date and time:
Date:
=INT(--SUBSTITUTE(SUBSTITUTE(A1,".","/",1),".","/",1) + TIME(6,0,0))
And format it mm/dd/yyyy
Time:
=MOD(--SUBSTITUTE(SUBSTITUTE(A1,".","/",1),".","/",1) + TIME(6,0,0)),1)
And format it hh:mm:ss.000 AM/PM
use text: =concatenate(text(a1,"MM"),text(a1,"DD"),text(a1,"YYYY") do the same for the other column =concatenate(text(a1,"HH"),text(a1,"MM"),text(a1,"SS")
That's pretty strange that you Excel will round off the milliseconds if you try and use a Date-Time format.
Enum DTValues
ReturnDate
ReturnTime
ReturnDateTime
End Enum
Function getDateTime(yyyymmdd_hh_mm_ss_000 As String, ReturnValue As DTValues) As Single
Dim arr
Dim mSecs As Single
yyyymmdd_hh_mm_ss_000 = Replace(yyyymmdd_hh_mm_ss_000, " ", ".")
yyyymmdd_hh_mm_ss_000 = Replace(yyyymmdd_hh_mm_ss_000, ":", ".")
arr = Split(yyyymmdd_hh_mm_ss_000, ".")
mSecs = arr(6) / 24 / 60 / 60 / 100
Select Case ReturnValue
Case ReturnDate
getDateTime = CSng(DateSerial(arr(0), arr(1), arr(2)))
Case ReturnTime
getDateTime = CSng(TimeSerial(arr(3), arr(4), arr(5))) + mSecs
Case ReturnDateTime
getDateTime = CSng(DateSerial(arr(0), arr(1), arr(2))) + CSng(TimeSerial(arr(3), arr(4), arr(5))) + mSecs
End Select
End Function
Sub ProcessDates()
Const WORKSHEET_NAME = "Sheet1"
Const FIRST_ROW = 2
Const SOURE_COLUMN = 1
Const DATE_COLUMN = 2
Const TIME_COLUMN = 3
Dim Target As Range
Dim arDate, arTime
Dim y As Long
With Worksheets(WORKSHEET_NAME)
Set Target = .Range(.Cells(FIRST_ROW, SOURE_COLUMN), .Cells(Rows.Count, SOURE_COLUMN).End(xlUp))
End With
arDate = Target.Value
arTime = Target.Value
For y = 1 To UBound(arDate)
arDate(y) = getDateTime(arDate(y), ReturnDate)
arTime(y) = getDateTime(arTime(y), ReturnTime)
Next
Target.EntireRow.Columns(DATE_COLUMN).Value = arDate
Target.EntireRow.Columns(TIME_COLUMN).Value = arTime
End Sub
New to VBA and lousy at it, so please be gentle!
I have the following code which gives the Long type variable "EIa" a value. I was getting a bunch of odd results later down the code so I put in some Debug.Print lines to find my issue and notice that when I Debug.Print the variable EIa, I get 0 but if I Debug.Print EXACTLY the expression that defines EIa, I get the expected value. Code below, any ideas?
'Calculate mA1:
'****************************************************************************************************
EIa = Etimber * ImatA / (Etimber * (ImatA + ImatB + ImatC + ImatD))
Debug.Print "EIa = "; EIa
Debug.Print "EIa = "; Etimber * ImatA / (Etimber * (ImatA + ImatB + ImatC + ImatD))
mA1 = 12 * 0.5 * (q1PSF * EIa) * bMat * LcantiA ^ 2 '12 puts this into lb-in
If LmatSymA = 0 Then
fbA1 = 0
Else
fbA1 = (mA1 * (0.5 * tMatA) / ImatA)
End If
The result of the expression is a kind of fractional, floating point number, but since you defined EIa as Long (a large integer), it gets truncated to zero upon assignment.
See Visual Basic Data Types.
I have a method I wrote in a VBA module
Public Function calcAscentTime()
IDepth = CInt(Sheets("Fundies").Range("B47"))
T = 0
T = T + 1 ' Add 1 minute for emergency
D = Math.Round((IDepth / 10) * 10) 'Round to Ceiling of nearest 10
half_depth = Math.Round(((D / 2) / 10) * 10, 0) 'Get where our first stop is
T = T + Math.Round((((D - half_depth) / 30) / 2) * 2) ' Ascend to first stop at 30ft/min
T = T + (half_depth / 10) ' 1 minute for every stop thereafter
What this does is take a value from Cell B47 on the "Fundies" worksheet and should return a value based on the calculations. I enter =calcAscentTime() into cell B48, expecting to get a value of 8(B47's value is 100), but get a return value of 0. What am I doing wrong?
ou're function isn't returning anything. Assigning the function name to the calculated variable should return the expected result (assuming you have everything else right). Something like:
Public Function calcAscentTime()
IDepth = CInt(Sheets("Fundies").Range("B47"))
T = 0
T = T + 1 ' Add 1 minute for emergency
D = Math.Round((IDepth / 10) * 10) 'Round to Ceiling of nearest 10
half_depth = Math.Round(((D / 2) / 10) * 10, 0) 'Get where our first stop is
T = T + Math.Round((((D - half_depth) / 30) / 2) * 2) ' Ascend to first stop at 30ft/min
T = T + (half_depth / 10) ' 1 minute for every stop thereafter
calcAscentTime = T
End Function
Keep in mind, you should probably Dim your variables to the proper type to avoid any kind of confusion / miss-casting by the compiler.