PB How to take the server time

Source: Internet
Author: User
Tags datetime sybase

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.