Timestamp substraction
Moderators: chulett, rschirm, roy
-
- Premium Member
- Posts: 108
- Joined: Sat Feb 05, 2005 6:52 pm
- Location: US
Timestamp substraction
Hi,
How can I substract 5 minutes from a timestamp and get the output.
Thanks in Advance,
Abhi
How can I substract 5 minutes from a timestamp and get the output.
Thanks in Advance,
Abhi
Hi,
Except searching for the answer in this forum....
you can use Iconv(...) to get the time to a DS internal representation subtract the time and use Oconv(...) to turn it back to timestamp format.
use the DS help on the mentioned routines.
IHTH,
Except searching for the answer in this forum....
you can use Iconv(...) to get the time to a DS internal representation subtract the time and use Oconv(...) to turn it back to timestamp format.
use the DS help on the mentioned routines.
IHTH,
Roy R.
Time is money but when you don't have money time is all you can afford.
Search before posting:)
Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
![Image](http://www.worldcommunitygrid.org/images/logo.gif)
Time is money but when you don't have money time is all you can afford.
Search before posting:)
Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
![Image](http://www.worldcommunitygrid.org/images/logo.gif)
Abhi,
The basic function for doing this is not complicated, but it is the exceptions that make it a bit difficult. It comes down to what the result of subtracting 5 minutes from "2005-01-01 00:04:00" should be.
The timestamp is usually in the form of a string. Using substrings and two calls to the ICONV function you can get the Julian date and seconds-since-midnight into 2 numeric variables. Then you can do your numeric subtraction and use the converse OCONV calls to rebuild your timestamp string.
The basic function for doing this is not complicated, but it is the exceptions that make it a bit difficult. It comes down to what the result of subtracting 5 minutes from "2005-01-01 00:04:00" should be.
The timestamp is usually in the form of a string. Using substrings and two calls to the ICONV function you can get the Julian date and seconds-since-midnight into 2 numeric variables. Then you can do your numeric subtraction and use the converse OCONV calls to rebuild your timestamp string.
-
- Premium Member
- Posts: 108
- Joined: Sat Feb 05, 2005 6:52 pm
- Location: US
Thanks for the replies,but I have to implement the following logic in the stage variable:
Using table1.strt_tm, table1.finishing_tm for a specific WORK_ID, Select the min(LAST_UPD_TMST) from table2 . Compare the min(LAST_UPD_TMST) to the WORK_DETAIL.strt_tm and WORK_DETAIL.finishing_tm. If it is between strt_tm - 5 minutes and finishing_tm, then move O (on-time). If Before the strt_tm - 5 minutes, then E (early). If After the finishing_tm, then L (Late). IF either strt_tm or finishing_tm are null, then N (no appointment)
please can anyone reply urgently .
Thanks.
Abhi
Using table1.strt_tm, table1.finishing_tm for a specific WORK_ID, Select the min(LAST_UPD_TMST) from table2 . Compare the min(LAST_UPD_TMST) to the WORK_DETAIL.strt_tm and WORK_DETAIL.finishing_tm. If it is between strt_tm - 5 minutes and finishing_tm, then move O (on-time). If Before the strt_tm - 5 minutes, then E (early). If After the finishing_tm, then L (Late). IF either strt_tm or finishing_tm are null, then N (no appointment)
please can anyone reply urgently .
Thanks.
Abhi
Abhi,
please remember that this is a common forum with those people who can answer volunteering them, and those who pose questions who eventually become those in the first group. If it is urgent then you are in the wrong place.
Back to your issue - Even though you can solve this in stage variables the logic is best put into a function call, it makes for some cleaner logic. It seems that a function to give you difference between two times would work. I am including a function that I just wrote to illustrate your problem as code. Please note that it contains no error checking, it assumes the dates come in correctly formatted and that StartDate/Time is less than EndDate/Time. It returns the minutes difference. You will need to expand upon the code in order to have it apply to your job, but it should suffice as a starting point.
please remember that this is a common forum with those people who can answer volunteering them, and those who pose questions who eventually become those in the first group. If it is urgent then you are in the wrong place.
Back to your issue - Even though you can solve this in stage variables the logic is best put into a function call, it makes for some cleaner logic. It seems that a function to give you difference between two times would work. I am including a function that I just wrote to illustrate your problem as code. Please note that it contains no error checking, it assumes the dates come in correctly formatted and that StartDate/Time is less than EndDate/Time. It returns the minutes difference. You will need to expand upon the code in order to have it apply to your job, but it should suffice as a starting point.
Code: Select all
MinutesDifference(StartTimeStamp,EndTimeStamp)
StartDate = ICONV(StartTimeStamp[1,10],'D4-YMD[4,2,2]')
StartTime = ICONV(StartTimeStamp[12,8],'MTS')
EndDate = ICONV(EndTimeStamp[1,10],'D4-YMD[4,2,2]')
EndTime = ICONV(EndTimeStamp[12,8],'MTS')
IF (StartDate=EndDate) THEN Ans = INT((EndTime-StartTime)/60)
ELSE
Ans = INT(((24*60*60)-StartTime)/60) ;** time to midnight
Ans += INT(EndTime/60) ;** add time from midnight to end
Ans += ((EndDate-StartDate-1)*24*60) ;** add days difference
END ;** of if-then-else same day
Search the forum as well next time before posting your question. You would have found that solutions were waiting for you.
viewtopic.php?t=85788
viewtopic.php?t=85788
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
-
- Premium Member
- Posts: 108
- Joined: Sat Feb 05, 2005 6:52 pm
- Location: US
Hi,
Thanks to all those who replied and gave suggestions. I know access to this forum is a privilege and not a right and I am very grateful to it
I am sorry if I made an earnest request but I will keep that in mind next time.
But, coming to my problem I may be wrong in expressing my question as I know how to compare two time stamps but the real thing is:
As Roy said I converted the timestamp to internal timestamp and Roy can you please tell me what would be the syntax for substracting 5 minutes from the internal time. It may seem simple but I have tried lot of things and they don't seem to work.
Thanks,
Sai.
Thanks to all those who replied and gave suggestions. I know access to this forum is a privilege and not a right and I am very grateful to it
I am sorry if I made an earnest request but I will keep that in mind next time.
But, coming to my problem I may be wrong in expressing my question as I know how to compare two time stamps but the real thing is:
As Roy said I converted the timestamp to internal timestamp and Roy can you please tell me what would be the syntax for substracting 5 minutes from the internal time. It may seem simple but I have tried lot of things and they don't seem to work.
Thanks,
Sai.
If you look at the post I referred, it subtracts two timestamps and gives the results in seconds.
Second, there is no "internal timestamp" value. There is internal date and internal time.
Third, if you substract two dates and have the results in seconds, the resulting number can be compared against 300 seconds to tell you if the two timestamps are within 5 minutes of each other.
Second, there is no "internal timestamp" value. There is internal date and internal time.
Third, if you substract two dates and have the results in seconds, the resulting number can be compared against 300 seconds to tell you if the two timestamps are within 5 minutes of each other.
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
-
- Premium Member
- Posts: 108
- Joined: Sat Feb 05, 2005 6:52 pm
- Location: US