Delphi require 4 digit year -
a user enter string value date. strtodate used convert string value datetime. if user enter's date 2 digit year date may parsed current century (20xx) or previous century (19xx).
to clear ambiguity, how require user enter 4 digit year?
if isfourdigityear(txbdate.text) date := strtodate(txbdate.text) else showmessage('enter date 4 digit year');
one possibility this:
function isfourdigityear(datestr : string ; datesep : char = '/') : boolean; var p : cardinal; begin datestr:=datestr+datesep; result:=true; repeat p:=pos(datesep,datestr); if p=5 exit; delete(datestr,1,p) until datestr=''; result:=false end;
it check there part of given string has 4 characters.
it won't check if part numerical (ie. contains digits). , require pass in seperator character used if want international - there countries use '-' date seperator, , other countries in world doesn't use strange m/d/y format, either d/m/y or y/m/d format (where "/" may "-" in countries).
if want international function checks if four-digit part in year part of valid date format, it'll need more complex parser. above may started, however...
Comments
Post a Comment