Solved

Using KOL library

Posted on 2001-08-22
9
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month6 days, 8 hours left to enroll

634 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