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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -