![]() |
#1
|
|||
|
|||
![]()
Hi All
And thanks in advanced for helping out. I have this code, I had it for almost 2 year, without realizing that it has a bug when calculating the date (Not the Time) Database is MSSQL Here is the scenario I have 2 fields Both Duty_From and Duty_To (DateTime Field) I need that when I change the time on the Duty_From field, the Duty_To field updates, based on the value of the Variable "Hours". Please note that on the code I am getting the Hours updated correctly, however the date in the Duty_To field always default to the number 24 For example if the employee's hours to work is 10 hours, and if the Duty_From field holds 08/28/2013 14:00, I get 08/24/2013 00:00 The Duty_To Hours updates correctly, but not the date. I would appreciate your help. I have no clue on how to get this resolve and hope you guys can help me. Thanks Here is the code Code:
var t1,t2:tdatetime; hours : Real; VarDuty_From : TDateTime; begin Try VarDuty_From := 08/28/2013; t1 := VarDuty_From; hours := 10; t2:=t1+((1/24/60)*60*hours); //Here is where I think I have the issue qryEmpl_Assignment.FieldByName('DUTY_FROM').AsString := formatDateTime('MM/DD/YYYY hh:nn',VarDuty_From); qryEmpl_Assignment.FieldByName('DUTY_TO').AsString := formatDateTime('MM/DD/YYYY hh:nn',t2); except //No Error want to display end; end; |
#2
|
|||
|
|||
![]()
Hi delphimpd,
First I hope you and your family are doing ok. Second I think your problem comes from the way you are incrementing the date by the number of hours. Try the following code as an example: Code:
var t1, t2 : TDateTime; hours : Int64; begin hours := 10; t1 := Now; //Start from any date you want. t2 := IncHour(t1,hours); //Increment the date by any number of hours you want. Showmessage(DateTimeToStr(t2)); //Show the new date.
__________________
Regards, Abdulaziz Jasser |
#3
|
|||
|
|||
![]()
Hi Jasser,
Thanks for your regards and I hope that your family is also doing good. Thanks for the response. Let me try your code. I do appreciate it. Regards |
#4
|
|||
|
|||
![]()
Hi Jasser,
Thanks for the help. I do appreciate it. Your recommendation worked very well. I hope it serves to others as well. Thank you so much my friend. Best regards |
#5
|
|||
|
|||
![]()
I am glad to hear that...and you are very welcome my friend.
__________________
Regards, Abdulaziz Jasser |
#6
|
|||
|
|||
![]()
Hi There again Jasser and thanks for the help.
Sorry for going back and forth on an old post. Using the same calculation as described before, but instead of whole number a decimal in the amount of hours such as 2.5, meaning that a person could take 2.5 hours, instead of 2 I am getting the hours from an edit field (See Value for hours), and then I convert the entry from a text to an integer and of course I get an error message saying that "2.5" is not a valid integer value. Can you or anyone tell me what can I do to get this to work when entering a whole or a decimal value? So this is what I do Code:
var t1, t2 : TDateTime; hours : Int64; begin hours := strToInt64(Edit1.Text);//The value here is 2.5 t1 := Now; //Start from any date you want. t2 := IncHour(t1,hours); //Increment the date by any number of hours you want. Showmessage(DateTimeToStr(t2)); //Show the new date. Regards |
#7
|
|||
|
|||
![]()
Try:
Code:
var t1, t2 : TDateTime; iMinutes : Int64; begin iMinutes := Trunc(StrToFloat(Edit1.Text) * 60); //Convert hours to minutes. t1 := Now; //Start from any date you want. t2 := IncMinute(t1,iMinutes); //This time it will be Minutes to increment. Showmessage(DateTimeToStr(t2)); //Show the new date.
__________________
Regards, Abdulaziz Jasser |
#8
|
|||
|
|||
![]()
Hi Jasser,
Thanks again. That worked great. Thanks so much Take care Regards, |
![]() |
Thread Tools | |
Display Modes | |
|
|