LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I add 1 month to a timestamp date?

I don't think that the argument that there is no "standard" way to do it means that no solution exists.  

 

As I mentioned in the OP, java does this with a calendar object that provides a means to hide the idiosyncrocies of handling dates while also providing options to the developer of how they want to manipulate the dates.http://docs.oracle.com/javase/7/docs/api/java/util/GregorianCalendar.html#add(int,%20int).    The roll() function seems to do exactly what I want, and I what I expected adding 1 month to the date/time record would have done.

Thanks for the quick replies, everyone, even if it included a small amount of snark for the behaviour of others.

 

0 Kudos
Message 11 of 27
(3,450 Views)

Please don't think that my answer was anything other than a light-hearted comment and wasn't to be taken too seriously, if it came across that way then I apologise!

 

NI and the LabVIEW community produce huge amounts of code that is publicly available for use (I've even written some myself!) but I think 'expecting' them to have already written a library when there isn't a huge demand for it (given the nature of the language as an engineering tool - it's not like you're likely to write a calendar application in LabVIEW). If you do think it's a worthwhile addition - that's what the Ideas Exchange is for! 🙂

 

NI themselves have to decide if they want to focus their efforts on improving the core of LabVIEW (e.g. performance/stability/hardware support/low-level functions) or writing code libraries (from that core functionality - such as advanced date/time manipulation). Personally, I'd rather they did that than spend lots of time and effort on things that I might not even use and leverage the community for everything else where there is a need for it.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 12 of 27
(3,435 Views)

Okay attached is a quick and dirty solution.  It will add the number of days that are in the current month, so the day stays the same and the month increments by one.  If there is a rollover where January 30th, just add enough to land on the last day of the month in February.  I think that is what you meant by truncate.  It doesn't currently detect leap year but the subVI could be modified to handle that.

Message 13 of 27
(3,417 Views)

no need to apologize - that is how I interpreted your comment initially and my response was in kind.   I was commenting more on the general feeling of the thread, although even that feeling was very mild.  This was overall quite helpful in understanding the answer to my question.

0 Kudos
Message 14 of 27
(3,415 Views)

Thanks, Hoovah, I appreciate it.

0 Kudos
Message 15 of 27
(3,407 Views)

Also note that Hoovah's VI doesn't take into account daylight savings time, so if you are counting on the time, it could be off an hour if you cross a time change in that month period.

Message 16 of 27
(3,411 Views)

@Matthew_Kelton wrote:

Also note that Hoovah's VI doesn't take into account daylight savings time, so if you are counting on the time, it could be off an hour if you cross a time change in that month period.


Oh thanks for mentioning that.  OP really was just talking about dates so I focused on that.  

 

If you are taking a time and adding a month, you could end up with some odd results.  Adding a month to 03:00 January 28th, makes 03:00 February 28th, but then adding a month to 02:00 January 29th would make 02:00 February 29th, which is an odd case where a time can go backwards, for a month to a later date.

0 Kudos
Message 17 of 27
(3,397 Views)

Here was my take on the problem.

 

Worked on it during lunch without checking the thread for updates.

 

My version should maintain the time between standard/savings and deals with shorter months. You can use a value of -1 for the DST field in a date/time rec to ignore DST.

 

One case not handled is leap year. 

 

 

 

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

0 Kudos
Message 18 of 27
(3,380 Views)

Replying to an old thread, but I use this... It handles the corner cases (Leap year).  This just adds 18 months as a constant.

 

Untitled.png

Message 19 of 27
(2,765 Views)

Thank you.

 

This was exactly what I was searching for.

0 Kudos
Message 20 of 27
(2,456 Views)