Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database Time Manipulation... Help

Status
Not open for further replies.

Rached

Programmer
Mar 30, 2003
54
DK
i know this is a simple thing, but can not figure out how to get it right.. so please help
i have two fields in an acces DB, starttime, and endtime with short time format, in which they blong to the same date. I do some routines on these values and goes fine untill i try to substract them..I want to get the total difference hours between them and put in in a float variable.
This is my code:
TTime total = 0;
//first read the fields as DateTime
TDateTime start_time = datamodule1->Query1->FieldByName("StartTime")->AsDateTime;
TDateTime end_time = datamodule1->Query1->FieldByName("EndTime")->AsDateTime;
//Then substract
total = (act_start_time - act_end_time);

now "total" is a Time variable, and i want to add it's value to another float some where else, and manipulate it further so how can i convert it and get a value like xx.xx? i know you can convert datetime to float, but i only want the time, and not dates since starttime and endtime already have the same date in the db. I hope it is clear, thanks.

 
I suspect that you will need to use DecodeTime. See for more info.

James P. Cottingham

When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity.
[tab][tab]Albert Einstein explaining his Theory of Relativity to a group of journalists.
 
Make total a TDateTime and just use the FormatString function. Like such:

total = (act_start_time - act_end_time);

AnsiString TimeStr = total.FormatString("hh");
int Hours = TimeStr.ToInt();

this will return the string version of hours in 2 digit format, not military. Check out the TDateTime->FormatString function in help. It will show you all the options for this. For instance, you could pass in "hh:mm:ss" and it will display like a typical digital clock.

Or use James' idea of DecodeTime. It works just as well.

Chris
 
actually i solved it by decoding the time, manipulating it and then encoding where needed.. was a very good idea and simple, thanks guy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top