Chức năng: Điều chỉnh thời gian thành giá trị chuẩn ISO để ghi vào dữ liệu
Ngôn ngữ: asp - Nhóm: database
CÚ PHÁP
formatteddate = DateDB(varDate)
Chuyển đổi về định dạng chuẩn YYYY/MM/DD. Thường được sử dụng với function SQL_date.
VÍ DỤ
<%
Dim a
a = DateDB("27/10/2006")
Response.Write a
'--- returns 2006/10/27
%>
ASP Code
<%
Private Function DateDB(byVal varDate)
If isDate(varDate) Then
Dim myYear
Dim myDay
Dim myMonth
vardate=CDate(varDate)
myYear = Year(varDate)
myDay = Day(varDate)
myMonth = Month(varDate)
If Len(myDay) = 1 Then myDay = "0" & myDay End if
If Len(myMonth) = 1 Then myMonth = "0" & myMonth End if
'--- transform date to standard DB type
DateDB = myYear & "/" & myMonth & "/" & myday
'--- add the time if available
If datepart("h", vardate) <> 0 OR datepart("n", vardate) <> 0 OR datepart("s", vardate) <> 0 Then
DateDB = DateDB & " " & hour(varDate) & ":" & minute(varDate) & ":" & second(varDate)
End if
Else
dataDB = NULL
End if
End Function '--- DateDB
%>