Software date processing

xiaoxiao2021-03-06  43

The problem exists in the software during the software. Its essence is a unified issue of client dates, application servers, and database server dates.

First, the client à application server

Take the value of the customer form single element date, you want the server to process, you must perform a string to date conversion.

This conversion process is usually displayed via System.convert.TodateTime (String).

Convert.TodateTime can support the year / month / day, month / day / year conversion. The separator can be used "-", "/", "."

But the format of day / month / year cannot be processed.

If the date string is converted to .NET Framework's DateTime failed, it will report the following error

This string is not identified as a valid DateTime.

The test results in .NET Chinese version, .NET English version. According to the breakpoint tracking prompt. The format in the date of the date in NET Framework is month / day / year.

Convert. TodateTime cannot be converted to day / month / year's date format. The impact thereof is. The system cannot handle the input day / month / year format. If the user enters, the default is to convert to moon / day / year. If the conversion is unsuccessful, the error is thrown. This feature for .NET Framework is also reasonable.

Second, the application server à client (server side assignment)

Many interface elements in the system have initial values, which are Date.ToshortDateString () assigned to page elements. This short date format is constrained by the date format set by the server, does not necessarily consistent with the client. This time you need to set a format string to set a date format.

The system also takes into account the problem of date format.

Plentysoft.ips.common.ipssysconst.date_Format

Public const string Date_Format = "YYYY-MM-DD";

Set the format of the date, although this format is currently written in the program. But it can also be easily changed to dynamically set by the program.

IPssysConst.date_Format is also used in many modules. But it is also not in this format in many modules. In the previous programmer's concept, the place where used is just just after he removed the date, there is no need to display the time.

Third, other systems for processing methods

SAP Business One can set a date format in the system settings. Visual entry is subject to this set format. The output is also used in this format.

The QAD system is an input format for the date control limit to the entries for the MM / DD / YY system must be in this legal range.

Fourth, the date format of the SQL Server2000 database

Under the default configuration, a date of the string is almost the same when writing to the database, like Convert.TodateTime, the database can support the year / month / day and month / day / year hidden test conversion. The separator can be identified with "-", "/", ".". But the format of day / month / year cannot be processed.

If it is a date conversion error in the database. Meet the following error:

The conversion from the CHAR data type to the DateTime data type causes the DATETIME value. The statement has been terminated.

Date format of the database. Simply set parameters to change. The following is an example of setting a date format in the database.

Set DateFormat MDY

Go

Declare @datevar datetime

Set @datevar = '12 / 31/98 '

SELECT @datevar

Go

Set DateFormat YDM

Go

Declare @datevar datetime

Set @datevar = '98 / 31/12 '

SELECT @datevar

Go

SET DATEFORMAT YMD

Go

Declare @datevar datetimeset @datevar = '98 / 12/31 '

SELECT @datevar

Go

SQL statement like this is very unscrupulous.

SELECT * from Table Where Date <2004-12-22 '

SQL like this is only correct under specific date format settings.

INSERT INTO TABLE (DATE) VALUES ('2004-1-25')

The above two examples have a problem with date format, and pay attention to when programming.

As the operating system of the client is a five-flowered, the operation habits of each user are also strange. If there is no limit to the date on the client, the client's date is directly to the database is very dangerous, the program is still can't work Small problems, but if the user is the intention of the user, the system's understanding is month / day, and the data is full.

The application server date to the database is generally implicitly implicit, and no additional processing is required. If there is a special date format, you only need to turn it with a format string.

The language version of the database is not limited, and there may be problems is that some default language versions can not meet the needs, reusing the set dateformat setting format.

V. Recommended solutions for system existing issues

Agreement: Requires the server side to use DD / MM / YYYY format.

Since we now currently enter the interface through the date control. So by improving the date control, it can be limited to a date format.

It is set to YYYY-MM-DD format, which is only concentrated in the control, and it is planned for 4 days. The main difficulty is that the date separator cannot be deepened. The value of the date, assignment problem. The control is simulated QAD date control.

In the date display output, the date of the date control, the date of the Date is displayed in the DataGrid, and the date displayed in the date of the report. Requirements must be used to format the date with a unified date formatted string plentysoft.ids.common.ipssysconst.date_Format formatted. There is a small amount of code that has not been formatted directly in the current system. It is mainly manifested to assign a value to the date control. The current report has been done, it is understood that it is also formatted if it is used in the future.

Advantages: As long as the date control restricts the legal format. The server-side program has little amount.

Disadvantages: The server-side system cannot adopt a system of days / month / annual format. Date format is dead, not humanized.

Workload: 6 people

6. The most comprehensive solution for system existing issues:

Entry in data. Interface layer -> The business logic layer adopts the system format set by the client system. Or entry the date data by the format set by the login user. The business logic layer is to resolve the correct date according to the user's settings. At the same time, it is necessary to set according to the date format of the server system. And the date setting of the database system. Establish a generic method of transformation.

Different date formats can be implemented in display on the date data display.

Advantages: You can fully respect the user's operating habits, because our system may use the same system in mainland and Hong Kong companies. If this is done, you can make users more convenient, or you can have different date formats for different users. .

Disadvantages: The amount of change is relatively large, not only interface controls, existing procedures, and underlying code processing will be changed. Also add the module set by the date.

Workload: Conservative estimation, program change test requires 1.5 months.

转载请注明原文地址:https://www.9cbs.com/read-55027.html

New Post(0)