下面是該函數...
'**********************************************************************************************************
'' @SDESCRIPTION: Gets an independent sql representation for a datetime string standardised by ISO 8601
'' @DESCRIPTION: If you want to create a sql statement containing a date query in the where clause,
'' use this function to create a datetime object.
'' EXAMPLE:
'' In Sql Server: Declare @timeTable TABLE (name int, starttime datetime)
'' In VBScript: sql = "SELECT * FROM timeTable WHERE starttime = " & date.toMsSqlDateFormat(cDate('2007-01-01 15:30:00'))
'' Results in: SELECT * FROM timeTable WHERE starttime = cast('2006-01-01T15:30:00' as datetime)
'' NOTE: only for MS SQL Server
'' @PARAM: dat [date]: the date/time you want to cast
'' @RETURN: [string] the formatted date string
'**********************************************************************************************************
public function toMsSqlDateFormat(dat)
if dat = empty then exit function
toMsSqlDateFormat = "cast('" & year(dat) & "-" & lib.custom.forceZeros(month(dat), 2) & "-" & _
padLeft(day(dat), 2, "0") & "T" & padLeft(hour(dat), 2, "0") & ":" & _
padLeft(minute(dat), 2, "0") & ":" & padLeft(second(dat), 2, "0") & "' as datetime)"
end function
'******************************************************************************************************************
'' @SDESCRIPTION: right-aligns a given value by padding left a given character to a totalsize
'' @DESCRIPTION: example: input: <em>22</em> -> output: <em>00022</em> (padded to total length of 5 with the paddingchar 0)
'' @PARAM: value [string]: the value which should be aligned right
'' @PARAM: totalLength [string]: whats the total Length of the result string
'' @PARAM: paddingChar [string]: the char which is taken for padding
'' @RETURN: [string] right aligned string.
'******************************************************************************************************************
public function padLeft(value, totalLength, paddingChar)
padLeft = right(clone(paddingChar, totalLength) & value, totalLength)
end function
public function clone(byVal str, n)
for i = 1 to n : clone = clone & str : next
end function
我知道SQL以自己的方式存儲日期,但不知道查詢分析器中是否存在隱式轉換,應該檢查實際格式是什麼。 – RoguePlanetoid 2009-09-30 13:27:29
如果你知道這一點,你是什麼意思與本機格式? – erikkallen 2009-09-30 13:51:25
我認爲這是我說的原生格式,而不是實際的原生格式 - 但是我正在尋找一種方法來複制日期,並認爲使用本機格式在SQL中會更好 - 但由於日期正在轉換,無論如何,我將會轉換它。 – RoguePlanetoid 2009-09-30 14:27:48