Home > Back-end >  Questions about database to store the date format
Questions about database to store the date format

Time:04-21

Question 1
A computer saving data, format is: 2021/4/19
B computer save the data, the format is: 2021-04-19
Results as A result, A computer query less than B input of data, B is not A data entry, in the case of not re-enter, how should solve?


Question 2
Can not mandatory, at the time of input data, the format of the computer must be the 2021-01-01 this format, this format, if not prohibited entry, or force the system format to the 2021-01-01 in this way,

CodePudding user response:

My application reference example, modified online application startup to modify system time format, you see if you can use:
Procedure TFormMain. MYSetDateTimeFormat;
Const
I=100;
Var
Buf: PChar;
P: ^ dwords.
The begin
GetMem (Buf, 100);
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, Buf, I);
//get the current user Settings, short date format,
If the Trim (string (Buf)) & lt;> Then 'yyyy/MM/dd'
The begin
SetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, PChar (' yyyy/MM/dd));
//set the short date format
//SetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, PChar (' yyyy ' 'in' the 'M' 'month' 'd' ' ' ', '));
//set the long date format to yyyy 'years' M' day ', 'month' d "(date) (month) (year)" must be enclosed in single quotes, Delphi string must use two single quotation marks,
SetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, PChar (HH: mm: ss "));
//set time format, 24-hour
SendMessageTimeout (HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_ABORTIFHUNG, 10, @ p);
//set must be called after the completion, notify the other program format has been changed, or even the application itself can't use the format of the new setting
end;
end;

CodePudding user response:

How did that happen? Date/time in memory said is consistent, only display format with different environment, the database has a date/time data types, you use the string to store the date/time?

CodePudding user response:

Another: understand the System. The SysUtils. FormatDateTime () function,

CodePudding user response:

Question 1:
When the system initialization, unified format specified date:
 
FormatSettings. ShortDateFormat:='- dd yyyy - mm;
FormatSettings. DateSeparator:='-';


Question 2
With problem 1
  • Related