Sign in to follow this  
Followers 0
kcmoss

Subtracing Date and Time

6 posts in this topic

I need to subtract a on  date and time stamp variable from another one to show how longs before the 2 date and times are equal so the operator can see how long they have to wait.  Any help would be appreciated.

Ken

Share this post


Link to post
Share on other sites

Suggest you look at  CALENDAR SUBTRACT: CSUB(731)

Share this post


Link to post
Share on other sites

CSUB will only subtract hours minutes and seconds.  Looking for a away to do date as well

Share this post


Link to post
Share on other sites

If you can use Structured text this should work:

(*I USED THE SAME TIME STAMP VARIABLES IN THE EQUATIONS BELOW WHICH ARE JUST THE PLC CLOCK ADDRESS IN MY PROGRAM, BUT THE 1 AND 2 LINES SHOULD BE YOUR TWO DIFFERENT TIME STAMP VARIABLE SETS, YOU COULD ALSO INCLUDE THE MONTH AND YEAR IN THE SAME MANNER IF NEEDED*)

UINT_DAY1:=STRING_TO_UINT(LEFT((WORD_TO_STRING(CLOCK_DD_HH)),2));
UINT_DAY2:= STRING_TO_UINT(LEFT((WORD_TO_STRING(CLOCK_DD_HH)),2));

(*SUBTRACT THE TWO VALUES FOR YOUR DAYS REMAINING RESULT*)

UINT_HH1:= STRING_TO_UINT(RIGHT((WORD_TO_STRING(CLOCK_DD_HH)),2));
UINT_HH2:= STRING_TO_UINT(RIGHT((WORD_TO_STRING(CLOCK_DD_HH)),2));

(*SUBTRACT THE TWO VALUES FOR YOUR HOURS REMAINING RESULT*)

UINT_MM1:=STRING_TO_UINT(LEFT((WORD_TO_STRING(CLOCK_MM_SS)),2));
UINT_MM2:= STRING_TO_UINT(LEFT((WORD_TO_STRING(CLOCK_MM_SS)),2));

(*SUBTRACT THE TWO VALUES FOR YOUR MINUTES REMAINING RESULT*)

UINT_SS1:= STRING_TO_UINT(RIGHT((WORD_TO_STRING(CLOCK_MM_SS)),2));
UINT_SS2:= STRING_TO_UINT(RIGHT((WORD_TO_STRING(CLOCK_MM_SS)),2));

(*SUBTRACT THE TWO VALUES FOR YOUR SECONDS REMAINING RESULT*)

I am not sure it is the best or cleanest way to do it, but it will work!

Share this post


Link to post
Share on other sites

Awesome Tiger Lily! Good to see you around.

Share this post


Link to post
Share on other sites

Thank you Jay!  I just had to do the same thing for one of my projects so happy to share!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0