Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

Using KOL library

Can anyone help me with date n time function using KOL library.

Basicly I want to print the current datetime as a string and secondly would like to return the minutes past the hour as a integer.

Hope you guys can help.

KOL homepage http://xcl.cjb.net
0
campid
Asked:
campid
  • 3
  • 3
  • 2
  • +1
1 Solution
 
GwenaCommented:
I know that 'now' returns the current date/time as a double .. maybe you can derive the data you need from this value..

function Now: TDateTime;
Returns local date and time on running PC.


type TDateTime = Double;
Basic date and time type. Integer part represents year and day (as is, i.e. 1-Jan-2000 is representing by value 730141, which is a number of days from 1-Jan-0001 to 1-Jan-2000 inclusively). Fractional part is representing hours, minutes, seconds and milliseconds of a day proportionally (like in VCL TDateTime type).

running this line
showmessage(Double2Str(now));
returns 730719.599368055826

There must be an easier way to do this...but you should be able to write some code to get the data you need  :-)

-->KOL suffers greatly from a lack of example code... :-/
0
 
campidAuthor Commented:
Don't I know it. They need someone to write a helpfile with a list of all functions and how to use um.

Its a great piece of kit though

I already knew about the now function returning a double but am having trouble breaking it down.

cheers
0
 
GwenaCommented:
Yup..
Vladimir is a brilliant programmer...but his documentation is rather poor :-) I'd like to see the source of any KOL programs you write... I have written a few..mostly very simple utils that run about 14.5kb to 25kb ... I just love the small exe files...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
edeyCommented:
Are you not using the sysutils unit?  If not then I'd think you'd have to encode the date/time yourself.  The time's the easy part, like so:

var
   time : extended;
   hours,mins,secs : integer;
begin
     time := now;
     time := (time-trunc(time)*24;
     hours := trunc(time);
     time := (time-trunc(time))*60;
     mins := trunc(time);
     time := (time-trunc(time))*60;
     secs := trunc(time);

The date, between leap years (remeber not all centuries are leap years) and variable length months, is a little more difficult to calculate.  Well, not so much hard as rather inelegant.

Much better would be to use the win32 api's getDateFormat & getTimeFormat.  They're declared in window.pas, I believe, so it's a good chance they're still available to you.

GL
Mike
0
 
GwenaCommented:
Hi edey :-)
  Using your code

editbox1.text := (int2str(hours)+' '+int2str(mins)+' '+int2str(secs));



Gives this result      '-16806536 -2 -11'
:-)
0
 
scrapdogCommented:
>time - trunc(time)

frac(time)

=)
0
 
campidAuthor Commented:
Guys,

Im not sure whats going on here. I just need to return the current minutes past the hour as an integer.

i.e 1 > 60

Cheers
0
 
edeyCommented:
try this:

time := now;
time := time*24*60;
time := frac(time);

then trunc(time*60) should be the number of min's.

GL
Mike
0
 
campidAuthor Commented:
Almost,
cheers guy. Here is how its done.

var
  curtime : extended;
begin
  curtime := now;
  curtime := curtime*24;
  curtime := frac(curtime);
  showmessage(int2str(trunc(curtime*60)));
end;
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now