Progress time question

Cjandura58

New Member
I am importing a file into our database that has the time in character format but the database field is time integer. In order to get the time correctly deposited into the field we came up with this;

time is "3:40:12AM"

15X60X60 = 54000
40X60 = 2400
12 = 12
----------
56412

56412 then translates into 3:40:12

We of course would rather not use this formula, we would like to find some simpler and yes sane way of converting a time string into actual intger time for input into the database.

Thank you in advance for any help you can give.

dizzy.gif

Carrie
NFCU
Vienna, VA
 

bendaluz2

Member
There are several variations of your method to do this, but I dont think there is anything significantly better.

btw, shouldnt 3:40:12AM be 3 x 60 x 60 not 15 x 60 x 60

Cjandura58 said:
I am importing a file into our database that has the time in character format but the database field is time integer. In order to get the time correctly deposited into the field we came up with this;

time is "3:40:12AM"

15X60X60 = 54000
40X60 = 2400
12 = 12
----------
56412

56412 then translates into 3:40:12

We of course would rather not use this formula, we would like to find some simpler and yes sane way of converting a time string into actual intger time for input into the database.

Thank you in advance for any help you can give.

dizzy.gif

Carrie
NFCU
Vienna, VA
 

Cjandura58

New Member
bendaluz2 said:
There are several variations of your method to do this, but I dont think there is anything significantly better.

btw, shouldnt 3:40:12AM be 3 x 60 x 60 not 15 x 60 x 60

Yes, we were also playing with military time and I just typed this fast this morning.

Thanks for the reponse.

CJ
 

arekp

New Member
In the past I wrote easy function to convert string to time.

I hope, it will be helpful :


function str2time return integer (input str as character):
def var out-time as integer init 0.
def var i as integer init 0.

if num-entries(str,":") <> 3 then return ?.
if index(str,"PM") > 0 then out-time = 12 * 3600.
str = replace(str,"pm","").
str = replace(str,"am","").

out-time = out-time + integer(entry(1,str,":")) * 3600 NO-ERROR.
out-time = out-time + integer(entry(2,str,":")) * 60 NO-ERROR.
out-time = out-time + integer(entry(3,str,":")) NO-ERROR.

return out-time.
end.

Arek

Cjandura58 said:
I am importing a file into our database that has the time in character format but the database field is time integer. In order to get the time correctly deposited into the field we came up with this;

time is "3:40:12AM"

15X60X60 = 54000
40X60 = 2400
12 = 12
----------
56412

56412 then translates into 3:40:12

We of course would rather not use this formula, we would like to find some simpler and yes sane way of converting a time string into actual intger time for input into the database.

Thank you in advance for any help you can give.

dizzy.gif

Carrie
NFCU
Vienna, VA
 

MHotovec

Member
I must be missing something important in the question and answers going on here - so you folks forgive me if I'm way off base with my answer.
But why not just use the HH:MM:SS format, that's what we do around here.

For instance:
def var v-test as char no-undo.
v-test = string(time,'hh:mm:ss').
disp v-test.

Mark

Cjandura58 said:
I am importing a file into our database that has the time in character format but the database field is time integer. In order to get the time correctly deposited into the field we came up with this;

time is "3:40:12AM"

15X60X60 = 54000
40X60 = 2400
12 = 12
----------
56412

56412 then translates into 3:40:12

We of course would rather not use this formula, we would like to find some simpler and yes sane way of converting a time string into actual intger time for input into the database.

Thank you in advance for any help you can give.

dizzy.gif

Carrie
NFCU
Vienna, VA
 
We of course would rather not use this formula, we would like to find some simpler and yes sane way of converting a time string into actual intger time for input into the database.
I think the above quote shows the important thing you are missing Mark. Converting integer to time string is easy. Going the other way isn't. ;)

I was advised at my Progress V6 to V7 jumpstart course in 1997 that Progress could offer a time-based data type. But instead they were going to finish developing "user-definable" data types. I'm still waiting.

If you thing converting string time to integer is difficult, try calculating elapsed string times with Progress (allowing for through midnight).
frustrated.gif
 

bendaluz2

Member
Yeah, I remember the whole calculating elapsed string times through midnight problem. Was certainly interesting :smokin:

Norman Biggar said:
I think the above quote shows the important thing you are missing Mark. Converting integer to time string is easy. Going the other way isn't. ;)

I was advised at my Progress V6 to V7 jumpstart course in 1997 that Progress could offer a time-based data type. But instead they were going to finish developing "user-definable" data types. I'm still waiting.

If you thing converting string time to integer is difficult, try calculating elapsed string times with Progress (allowing for through midnight).
frustrated.gif
 

doreynie

Member
Hi, try this:

def var c as char no-undo.
def var tHours as integer extent 24.
def var tMinutes as integer extent 60.
def var iTime as integer.
define variable iTel as integer no-undo.
assign
tHours[24] = 0
tHours[1] = 1 * 3600
tHours[2] = 2 * 3600
tHours[3] = 3 * 3600
tHours[4] = 4 * 3600
tHours[5] = 5 * 3600
tHours[6] = 6 * 3600
tHours[7] = 7 * 3600
tHours[8] = 8 * 3600
tHours[9] = 9 * 3600
tHours[10] = 10 * 3600
tHours[11] = 11 * 3600
tHours[12] = 12 * 3600
tHours[13] = 13 * 3600
tHours[14] = 14 * 3600
tHours[15] = 15 * 3600
tHours[16] = 16 * 3600
tHours[17] = 17 * 3600
tHours[18] = 18 * 3600
tHours[19] = 19 * 3600
tHours[20] = 20 * 3600
tHours[21] = 21 * 3600
tHours[22] = 22 * 3600
tHours[23] = 23 * 3600
tMinutes[60] = 0
tMinutes[1] = 60 * 1
tMinutes[2] = 60 * 2
tMinutes[3] = 60 * 3
tMinutes[4] = 60 * 4
tMinutes[5] = 60 * 5
tMinutes[6] = 60 * 6
tMinutes[7] = 60 * 7
tMinutes[8] = 60 * 8
tMinutes[9] = 60 * 9
tMinutes[10] = 60 * 10
tMinutes[11] = 60 * 11
tMinutes[12] = 60 * 12
tMinutes[13] = 60 * 13
tMinutes[14] = 60 * 14
tMinutes[15] = 60 * 15
tMinutes[16] = 60 * 16
tMinutes[17] = 60 * 17
tMinutes[18] = 60 * 18
tMinutes[19] = 60 * 19
tMinutes[20] = 60 * 20
tMinutes[21] = 60 * 21
tMinutes[22] = 60 * 22
tMinutes[23] = 60 * 23
tMinutes[24] = 60 * 24
tMinutes[25] = 60 * 25
tMinutes[26] = 60 * 26
tMinutes[27] = 60 * 27
tMinutes[28] = 60 * 28
tMinutes[29] = 60 * 29
tMinutes[30] = 60 * 30
tMinutes[31] = 60 * 31
tMinutes[32] = 60 * 32
tMinutes[33] = 60 * 33
tMinutes[34] = 60 * 34
tMinutes[35] = 60 * 35
tMinutes[36] = 60 * 36
tMinutes[37] = 60 * 37
tMinutes[38] = 60 * 38
tMinutes[39] = 60 * 39
tMinutes[40] = 60 * 40
tMinutes[41] = 60 * 41
tMinutes[42] = 60 * 42
tMinutes[43] = 60 * 43
tMinutes[44] = 60 * 44
tMinutes[45] = 60 * 45
tMinutes[46] = 60 * 46
tMinutes[47] = 60 * 47
tMinutes[48] = 60 * 48
tMinutes[49] = 60 * 49
tMinutes[50] = 60 * 50
tMinutes[51] = 60 * 51
tMinutes[52] = 60 * 52
tMinutes[53] = 60 * 53
tMinutes[54] = 60 * 54
tMinutes[55] = 60 * 55
tMinutes[56] = 60 * 56
tMinutes[57] = 60 * 57
tMinutes[58] = 60 * 58
tMinutes[59] = 60 * 59
.

repeat iTel = 0 to 3600:

assign
c = string(iTel,"hh:mm:ss")
iTime = tHours[if integer(substring(c,1,2)) eq 0 then 24 else integer(substring(c,1,2))]
+ tMinutes[if integer(substring(c,4,2)) eq 0 then 60 else integer(substring(c,4,2))]
+ integer(substring(c,7,2)).
display c iTime.
pause 1 no-message.
end.
 
Top