bklunder
6th April 2010, 18:49
I'm trying to figure out how long ago a product was built.
We have some custom software that scans a serial number (the serial number field is custom). When the serial number is scanned we call a library that inserts the date and time into a table. Now I want to take these two fields and compare that to the current date and time to find the difference. I've been working with dte(), time.num() and date.num() but not having much luck. Can anyone steer me in the right direction?
Any help would be appreciated.
Thanks
Bert
mark_h
6th April 2010, 19:38
Date.num() will generate a date. Now if you get the other date into the same format you can just subtract the two dates. What is the format of your date and time in the table? Typically in 4c4 we just use a tcdate as our format, then have a separate field for the time(if we even tract the time).
bdittmar
6th April 2010, 20:24
I'm trying to figure out how long ago a product was built.
We have some custom software that scans a serial number (the serial number field is custom). When the serial number is scanned we call a library that inserts the date and time into a table. Now I want to take these two fields and compare that to the current date and time to find the difference. I've been working with dte(), time.num() and date.num() but not having much luck. Can anyone steer me in the right direction?
Any help would be appreciated.
Thanks
Bert
Hello Bert,
dte$() gives date and time as MMDDYYHHMMSS
month-month-day-day-year-year-hour-hour-min-min-sec-sec
This is what is stored after scan ?
With num.to.date$(date.num(),0) you'll get:
The actual date formated as string as DDMMYY
time.num() are the seconds 'til midnight.
-----------------------
If you only need to calculate the days between you can use:
diffdays = date.to.num(lval(dte.field(5;2)),lval(dte.field(1;2)),lval(dte.field(3;2))) - date.num()
Hope i have set all braces at right position.
Regards
bklunder
6th April 2010, 21:40
Thanks for the quick replies. I should be a little clearer on my request.
I need to know how long a go a serial number was scanned because we shouldn't ship a unit until 24 hours after it was made (curing times etc).
My library script has a select statement that populaltes a table with the following:
string curr.time.and.date(12)
string curr.time(6)
curr.time.and.date = dte$()
curr.time = curr.time.and.date(7;6)
select *
from tdwrt500
where tdwrt500._index1 = {:serial.number}
selectempty
tdwrt500.serl = serial.number
tdwrt500.date = date.num()
tdwrt500.time = lval(curr.time)
endselect
So if a unit is built at 23:50:23(HH:MM:SS) on April 5 I will have the following data in the table:
DATE: 05-APR-10
TIME: 235023
If check in the morning of the 6th at 07:00:23 with a date.num() - tdwrt500.date I will get a result of 1. I need it to give me a result of 07:10:00 (less than 1 day or 24 hours).
Is this possible?
bdittmar
6th April 2010, 22:51
Hello,
i do'nt have a BaaN system in front yet.
I'll check the way your requirement will be solved.
Idea:
Date scanned and time scanned is stored in table.
so
date.num() will give the actual day (date).
time.num() will give the seconds since 00:00:00 for the current day.
Maybe with a little bit calculating it will be possible.
I'll give you some hints the next two days, or someone out there has a ready solution?
Regards
rahul.kolhe22
7th April 2010, 09:07
Hi Bert,
I have got a logic which is mentioned below:
curr.time.and.date = dte$()
curr.time = curr.time.and.date(7;6)
( (date.num() - tdwrt500.date) = 1) ? ((tdwrt500.time > curr.time) ? 1 : 0) : (date.num() - tdwrt500.date)
The above expression will return
0 : if date is not changed or if changed, 24 hours have not passed on
>0 : difference between the days.
I have myself not used this code, but I think it will work out for you.
Regards,
--Rahul.
manish_patel
7th April 2010, 13:11
I have myself not used this code, but I think it will work out for you.
Hi Rahul,
I think; there is minor change in condition required as below.
((date.num() - tdwrt500.date) = 1) ? ((tdwrt500.time <= curr.time) ? 1 : 0) : (date.num() - tdwrt500.date)
rahul.kolhe22
7th April 2010, 13:16
Hi Manish,
Thanks a lot for rectifying me.
Regards,
--Rahul
bklunder
7th April 2010, 17:38
Thanks for the code.
It appears to be doing something. It is giving me either a 0 or a 2 depending on the date / time given. This is a good thing. I'm a little confused. What do the '?' and the ':' represent in this statement?
Thanks again for the help.
Bert
mark_h
7th April 2010, 17:58
It is like a if then else statement. If the statement is true do the ? statement else do the : statement. Kind of like that.
bklunder
7th April 2010, 18:16
That's very interesting. Thanks everyone.
bdittmar
7th April 2010, 18:51
Hello,
as attachment a way to calculate the differences, shown as Excel sheet.
Break all to seconds an calculate with them.
This will do the trick.
Regards