The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Date Change Function

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000