Author: Xingda Computer technology company (www.study01job.com) Guo Baoli
When developing a C/S architecture application, the date should be obtained from the server to ensure the accuracy of the data. The following is a complete public function to get the server time.
/*-----------------------------------------------------------------------
* Function Name: DateTime gf_getsysdate (String As_dbms)
* Function Description: Get the server's date time (DateTime)
* parameter meaning: The database DBMS used by As_dbms
* Return Value: DateTime type, System date
* Call Example: Ldt_today = Gf_getsysdate (Sqlca.dbms)
* Writing staff: Guo Baoli
* Date of preparation: 2004.7.9
*-----------------------------------------------------------------------*/
DateTime ldt_date
String Ls_sql
Choose case lower (AS_DBMS)
Case "Oracle"
Oracle
Ls_sql = "Select Sysdate from Sys.dual"
Case "SQL Server"
MS SQL Server
Ls_sql = "Select Now ()"
Case "Sybase"
Sybase
Ls_sql = "Select GetDate ()"
Case Else
Ls_sql = "Select Now ()"
End Choose
Declare l_cursor dynamic cursor for SQLSA;
Prepare Sqlsa From:ls_sql;
Open dynamic l_cursor;
If Sqlca.sqlcode = 0 Then
Fetch L_cursor into:ldt_date;
End If
If Sqlca. SQLCode <> 0 Then
MessageBox ("error message", "Error in the function gf_get_sysdate () Run-time database!")
Ldt_date = Datetime (Today (), now ())
End If
Close l_cursor;
Return ldt_date