T O P I C R E V I E W |
LabTalk user |
Posted - 10/21/2010 : 11:47:11 AM Origin Ver. and Service Release (Select Help-->About Origin): 8.1 SR3 Operating System: Windows XP
I have been tasked with writing a function which accepts a date in the form JAN01, 2011 and then adds x number of months to said date. I've been trying to think of ways to do this and my brain hasn't come up with anything. If anyone has any ideas that would be great.
Thanks! |
2 L A T E S T R E P L I E S (Newest First) |
LabTalk user |
Posted - 10/22/2010 : 6:57:03 PM That is exactly what I was looking for. I can take your first example and tailor it to exactly what I need. Thank you so much for the help.
Thanks again! |
greg |
Posted - 10/21/2010 : 6:04:28 PM Days would be easy:
// BEGIN SCRIPT string str$ = "JAN01,2011"; // Input the date str.replace(',',' '); // Replace ',' jdn = date(%(str$),"MMMdd yyyy"); // Find the julian day number jdn += 365; // Add 365 days str$ = $(jdn,D0); // Get the new date as a string ty str$; // Output the new date // END SCRIPT
Our date( ) function cannot handle ',' so I replaced ',' with ' '. Since the date function returns days, it's easy to add days and get the date string.
The problem is : What exactly is a month? The answer depends on which month(s) we are talking about. This problem is compounded by leap years.
If you literally only care about months, then this does it: // BEGIN SCRIPT string str$ = "JAN28,1986"; addmonths = 264; str.replace(',',' '); jdn = date(%(str$),"MMMdd yyyy"); day = day(jdn,2); // Get the day of the month month = month(jdn); // Get the month year = year(jdn); // Get the year addyears = int(addmonths/12); // Find the number of years added addmonths = mod(addmonths,12); // And remaining months to add newjdn = date($(month+addmonths)/$(day)/$(year+addyears)); str$ = $(newjdn,D0); ty str$; // END SCRIPT
|
|
|