
'(强制)转换成长整数
Function GetLong(Expression)
    Select Case LCase(TypeName(Expression))
    Case "nothing"
        GetLong = 0
    Case "null"
        GetLong = 0
    Case "empty"
        GetLong = 0
    Case "boolean"
        GetLong = CLng(Expression)
    Case "field"
        GetLong = GetLong(Expression.Value)
    Case "string"
        If IsNumeric(Expression) Then
            GetLong = CLng(Expression)
        Else
            GetLong = 0
        End If
    Case Else
        GetLong = CLng(Expression)
    End Select
End Function

'(强制)转换成双精度浮点数
Function GetDouble(Expression)
    Select Case LCase(TypeName(Expression))
    Case "nothing"
        GetDouble = 0
    Case "null"
        GetDouble = 0
    Case "empty"
        GetDouble = 0
    Case "boolean"
        GetDouble = CDbl(Expression)
    Case "field"
        GetDouble = GetDouble(Expression.Value)
    Case "string"
        If IsNumeric(Expression) Then
            GetDouble = CDbl(Expression)
        Else
            GetDouble = 0
        End If
    Case Else
        GetDouble = CDbl(Expression)
    End Select
End Function

'(强制)转换成字符串
Function GetString(Expression)
    Select Case LCase(TypeName(Expression))
    Case "nothing"
        GetString = ""
    Case "null"
        GetString = ""
    Case "empty"
        GetString = ""
    Case "boolean"
        GetString = CStr(Expression)
    Case "field"
        GetString = GetString(Expression.Value)
    Case Else
        GetString = CStr(Expression)
    End Select
End Function

'(强制)转换成日期 yyyy-mm-dd
Function GetDate(Expression)
	Dim dtmDate,y,m,d
	If IsDate(Expression) Then
		dtmDate = CDate(Expression)
	Else
		dtmDate = Now
	End If
	
	y = Year(dtmDate)
	m = Right("0" & Month(dtmDate),2)
	d = Right("0" & Day(dtmDate),2)
	
	GetDate = y & "-" & m & "-" & d
	
	If Expression = -1 Then
		GetDate = y & "-" & m & "-01"
	End If
	
End Function

'(强制)转换成日期 yyyy-mm-dd
Function GetDateString(Expression)
    Dim sValue
    If IsDate(Expression) Then
        GetDateString = Year(Expression) & "-" & Right("0" & Month(Expression),2) & "-" & Right("0" & Day(Expression),2)
    Else
        sValue = GetString(Expression)
        Select Case Len(sValue)
        Case 4
            sValue = Year(Now) & "-" & Mid(sValue, 1, 2) & "-" & Mid(sValue, 3, 2)
        Case 6
            sValue = Mid(Year(Now), 1, 2) & Mid(sValue, 1, 2) & "-" & Mid(sValue, 3, 2) & "-" & Mid(sValue, 5, 2)
        Case 8
            sValue = Mid(sValue, 1, 4) & "-" & Mid(sValue, 5, 2) & "-" & Mid(sValue, 7, 2)
        End Select
        If Not IsDate(sValue) Then
            GetDateString = ""
        Else
            GetDateString = Year(sValue) & "-" & Right("0" & Month(sValue),2) & "-" & Right("0" & Day(sValue),2)
        End If
    End If
End Function


'(强制)转换成日期时间 yyyy-mm-dd hh:mm:ss
Function GetDateTime(Expression)
	Dim dtmDate,y,m,d,hh,mm,ss
	If IsDate(Expression) Then
		dtmDate = CDate(Expression)
	Else
		dtmDate = Now
	End If
	
	y = Year(dtmDate)
	m = Right("0" & Month(dtmDate),2)
	d = Right("0" & Day(dtmDate),2)
	hh = Right("0" & Hour(dtmDate),2)
	mm = Right("0" & Minute(dtmDate),2)
	ss = Right("0" & Second(dtmDate),2)
	
	GetDateTime = y & "-" & m & "-" & d & " " & hh & ":" & mm & ":" & ss
End Function

Function JIsDate(Expression)
	JIsDate = IsDate(Expression)
End Function


'求日期之差
Function DateDiff(d1,d2)

	If IsDate(d1) Then
		d1 = CDate(d1)
	Else
		d1 = Now
	End If	

	If IsDate(d2) Then
		d2 = CDate(d2)
	Else
		d2 = Now
	End If	

	DateDiff = d1-d2
	
End Function
function JDateAdd(sType,sNum,sDate)
	sDate=GetDate(sDate)
	sNum=GetLong(sNum)
	JDateAdd=DateAdd(sType,sNum,sDate)
end function

function JFormatNumber(Expression,nNum)
	Expression = GetDouble(Expression)
	If Expression = 0 Then
		JFormatNumber = "0"
		Exit Function
	End If
	nNum = GetLong(nNum)
	JFormatNumber=FormatNumber(Expression,nNum,-1)
end function 
function JIsNumeric(sValue)
	if IsNumeric(sValue) then
		JIsNumeric=true
	else
		JIsNumeric=false
	end if
end function