LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Manipulating Months Difference

Hi everyone... .I have a vi in which I need to subtract 4 months from the date entered in a timestamp control. However the number of days varies depending on the specific month and year that was entered in the control...

For example if I want to subtract 6 months from the entered date I would need the equivalent of the following:

 

DateDiff(Month,-6,”2009-04-25”)

Any ideas on how to accomplish this???? The time date functions in Labview are all seconds based and I cannot write a constant number of seconds to subtract...

0 Kudos
Message 1 of 5
(3,454 Views)
I recently wrote and uploaded a VI to do something close in response to a similar question, see here.  It will add any amount of time, not just months but should be quick to modify for subtraction (maybe you can just provide a negative number of months, I haven't tested that).   It hasn't been thoroughly tested but is simple enough that if there are bugs you should be able to resolve them easily.
Message Edited by nathand on 05-13-2009 10:01 AM
Message 2 of 5
(3,439 Views)
Here is an example that I have just written for you. It is not tested to 100%.
0 Kudos
Message 3 of 5
(3,428 Views)

nathand wrote:
I recently wrote and uploaded a VI to do something close in response to a similar question, see here.  It will add any amount of time, not just months but should be quick to modify for subtraction (maybe you can just provide a negative number of months, I haven't tested that).   It hasn't been thoroughly tested but is simple enough that if there are bugs you should be able to resolve them easily.
Message Edited by nathand on 05-13-2009 10:01 AM

 

I have taken the liberty of linking the image of your suggested code below.

 

 

 

 

That is a good start and should meet most situations unless your app has to take into concideration DST changes. In that case the constant "24" hours in a day is not always true (one day has 23 hours the other day has 25 hours).*

 

The other complication that comes inot play is that the dates when DST is turned on and off is dictated by laws that can and do change. THese changes end up in updates to the OS which LV uses to convert the time in seconds into a standard human form.

 

So the only method I have run across that always works is an interactive version that subtracts an hour at a time and then tests the new time to see if it is close to what we want. I saw "close" because if you are doing this check at 2:15 in the moning, three months prior to that time and date the "two-o-clock" hour may or may not exist!

 

I am open to hearing about other approach to the challenge of time so post way if you have ideas!

 

Ben

 

 

* I for the most part like the ideas that Ben Franklin came up with but the whole DST is not one of my forvorites.

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 5
(3,426 Views)
Playing with my example, you will see the +-1 hour effect of the DST changes mentionned by Ben.
0 Kudos
Message 5 of 5
(3,424 Views)