If the Windows system's short date format is "Yyyy/m/d", execute the following code to give an error: 2013-01-29 00:00:00 is not a valid date
Procedure Tfrmquerysale.formshow (Sender:tobject);
Var
sdate:string;
Begin
inherited;
The default check day sales data
Sdate: = FormatDateTime (' Yyyy-mm-dd ', now);
Datetimepicker1.datetime: = strtodatetime (sdate + ' 00:00:00 ');
Datetimepicker2.datetime: = strtodatetime (sdate + ' 23:59:59 ');
Find (Trim (Edtbillid.text), Datetimepicker1.datetime, datetimepicker2.datetime);
Edtbillid.setfocus;
End
How to solve?
Procedure Tdmcommonfun.setsysdateformat;
Begin
Format a short date for a Windows system
SetLocaleInfo (Locale_system_default, locale_sshortdate, ' yyyy-mm-dd ');
Application.updateformatsettings: = False;
Set the date time format used by the program itself
Longdateformat: = ' yyyy-mm-dd ';
Shortdateformat: = ' yyyy-mm-dd ';
Longtimeformat: = ' hh:nn:ss ';
Shorttimeformat: = ' hh:nn:ss ';
DateSeparator: = '-';
TimeSeparator: = ': ';
End
Executes the above code when the program is initialized, regardless of how the short date format of Windows is set no longer affects
Delphi program.
Xe2 above version, the code should be changed:
Procedure Setsysdateformat;
Var
Fs:tformatsettings;
Begin
Format a short date for a Windows system
SetLocaleInfo (Locale_system_default, locale_sshortdate, ' yyyy-mm-dd ');
Application.updateformatsettings: = False;
Set the date time format used by the program itself
Fs. Longdateformat: = ' yyyy-mm-dd ';
Fs. Shortdateformat: = ' yyyy-mm-dd ';
Fs. Longtimeformat: = ' hh:nn:ss ';
Fs. Shorttimeformat: = ' hh:nn:ss ';
Fs. DateSeparator: = '-';
Fs.timeseparator: = ': ';
End
Http://www.cnblogs.com/hnxxcxg/archive/2013/01/30/2882672.html
Let the Delphi program be unaffected by the Windows date format (using the SetLocaleInfo function and application.updateformatsettings)