Every time I use strtodate or datetostr, I am always worried.

Source: Internet
Author: User
Every time I use strtodate or datetostr, I always worry about developing and applying VCL components.
Http://www.delphi2007.net/DelphiVCL/html/delphi_20061220141719247.html
Every time I use strtodate or datetostr, I am always worried.

Because my data is sent to the server using datetostr to convert it into a string.

The server then converts strtodate to tdate

Now there is no problem. I am afraid that if the date format of the client is different from that of the server, the conversion will fail. What should I do?

Is there a unified approach?
I know that formatdatetime can be used to generate a string in the specified format.
But what if I convert this string to tdate? Strtodate may not work.

It is better to use formatdatetime for conversion, such as formatdatetime ('yyyymmdd', now (). If it is an SQL Server, the database will identify and convert the strings by itself, which has little to do with it.

If the client and server are both yours

InProgramDuring initialization

Required dateformat: = 'yyyy-Mmm ....
Longdateformat: = 'yyyy-Mmm ....


Give the two global values a value, so that the date format cannot be changed by the system.



The unified formatdatetime standard, for example, can be used to solve the above step!

Why do we need to convert it to a string? datetime is a floating point value. Just transfer it directly.

Passing a value should be faster than wearing a character!

I must pass it to string. The system needs

Convert date to double, double and then convert string! Use double to upload data!
To the server, convert string to double, double and then to date!

In the program, use the formatdatetime ('yyyy-mm-dd', now ())
This ensures that the format is consistent.
If datetostr is used, it sometimes contains Chinese Characters in strings (I have met it)
So I think formatdatetime is better.

Convert date to double, double and then convert string! Use double to upload data!

It's too long to convert double to string.

In the program, use the formatdatetime ('yyyy-mm-dd', now ())
This ensures that the format is consistent.
If datetostr is used, it sometimes contains Chinese Characters in strings (I have met it)
So I think formatdatetime is better.
------------------------
The key is to use formatdatetime ('yyyy-mm-dd', now ())
How to convert the string to tdatetime?

If it is an SQL Server database, it is not ideal to transmit data of the double type because the time starting point defined by SQL Server and Delphi is inconsistent. The difference is several days. You can check it by yourself.
Select convert (datetime, 0) ---- "00:00:00. 000
Datetimepicker1.datetime: = 0 ---- "1899-12-30

So we can use record or list packaging... to separate the year, month, and day into different fields.
For soap communication, it is easier to directly compress into XML packages.

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.