Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread DateTime calculations in EWB
Wed, Aug 22 2012 3:23 AMPermanent Link

Uli Becker

I want to validate a Date entered by a user. I can't see how to
calculate with DateTime in EWB?

E.g.: (pseudocode)

if StrToDate(edMyDate.text) > date + 90 then...

thanks.

Uli
Thu, Aug 23 2012 4:15 AMPermanent Link

Mark Brooks

Slikware

Avatar

<<I want to validate a Date entered by a user. I can't see how to
calculate with DateTime in EWB?>>

TDateTime's are really just integers so you can add and subtract them. For example, I have the following code to return a string representation of "some time ago":

function CastrumDateTimeAgoToStr(const ADateTime: DateTime): string;
var
 DT: integer;
begin
 
 // Never

 if integer(ADateTime) = 0 then
   begin
     Result := 'Never';
     exit;
   end;

 DT := (integer(Now) - integer(ADateTime)) div 1000;
 
 // Less then 60 seconds

 if DT < 60 then
   Result := 'Less then a minute ago'

 // Less than one hour

 else if DT < (60 * 60) then
   Result := IntToStr(DT div 60) + ' minute(s) ago'

 // Less than one day

 else if DT < (60 * 60 * 24) then
   Result := IntToStr(DT div (60 * 24)) + ' hour(s) ago'

 else
   Result := IntToStr(DT div (60 * 60 * 24)) + ' day(s) ago';
end;

Hope this helps
Mark
Thu, Aug 23 2012 4:37 AMPermanent Link

Uli Becker

Mark,

> Hope this helps

Yes, it does!

I have to get used to "think" in Javascript. Smile

Thanks Uli
Image