Solved

Using KOL library

Posted on 2001-08-22
9
175 Views
Last Modified: 2010-04-06
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
Comment
Question by:campid
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 5

Expert Comment

by:Gwena
ID: 6415191
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
 

Author Comment

by:campid
ID: 6415713
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
 
LVL 5

Expert Comment

by:Gwena
ID: 6415876
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:edey
ID: 6416287
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
 
LVL 5

Expert Comment

by:Gwena
ID: 6416329
Hi edey :-)
  Using your code

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



Gives this result      '-16806536 -2 -11'
:-)
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 6416347
>time - trunc(time)

frac(time)

=)
0
 

Author Comment

by:campid
ID: 6426092
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
 
LVL 6

Accepted Solution

by:
edey earned 30 total points
ID: 6426654
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
 

Author Comment

by:campid
ID: 6426989
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question