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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 date to increment of a year
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

5*10

Germany
Posts

Posted - 08/19/2005 :  11:16:19 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): OriginPro 7G SR4
Operating System:win 2000

Hi,
I have a little problem to find a function, which transform a date in increments of a year or so.
The Date has the format

dd.mm.yyyy hh:mm:ss

It will be nice if the solution of this gives me a value like

0,00145 Years,

or

1234,45 seconds.
Is there a function in Labtalk, OriginC that I can use. If not then I will think about a loop to calculate it.

Greets 5*10

cpyang

USA
1406 Posts

Posted - 08/21/2005 :  2:53:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I can show you how to do this in Origin C, but you probably need Origin 7.5 or later,

 
// assume strDate = dd.MM.year hh:mm:ss format
void dd(string strDate, string strYear)
{
string strDateFormat = "dd'.'MM'.'yyyy hh':'mm':'ss";
double yy;

if( str_to_date_custom(strDate, strDateFormat, &yy) )
{
string strDateRef = "1.1." + strYear + " 00:00:00";
double y0;
if(str_to_date_custom(strDateRef, strDateFormat, &y0))
{
printf("date offset from start of year %s is %g days\n", strYear, yy - y0);
return;
}
}
out_str("error in date format");
}




To test, enter

dd "1.1.2005 23:34:02" 2005

should print out

date offset from start of year 2005 is 0.981968 days

Date is internally represented as Julian Days, so once converted to Julian Days, you can calculate whatever you need to.

CP



Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000