Solved

Using KOL library

Posted on 2001-08-22
9
172 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 6

Expert Comment

by:edey
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Expert Comment

by:Gwena
Comment Utility
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
Comment Utility
>time - trunc(time)

frac(time)

=)
0
 

Author Comment

by:campid
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now