-
July 26th, 2010, 03:18 PM
#1
Manipulating Date and Time
I have a file which has 1000 line data in format:
Code:
01/02/1999,13,4
01/05/2003,4,7
01/16/2004,8,6
09/08/2005,8,5
I need to find the difference between consecutive rows to study the change for columns 2 and 3 over the available period of time.
So, the question is:
(1) How do I read the data so that I can create an array A(4x3) with column 1 of date, and columns 2 and 3 of other quantities so that I can do operations like A[4][1] - A[1][1], etc. and get the difference in unit of days between any two rows for column 1?
-
July 26th, 2010, 03:28 PM
#2
Re: Manipulating Date and Time
Read the line and after that, cut it up in parts.
-
July 26th, 2010, 03:49 PM
#3
Re: Manipulating Date and Time
I was able to use fscanf and read the pieces of month, day, year and 2 other quantities. But, I feel that with this information I would need to create a separate function so that it can find difference between dates of two rows. Is there no function that I can directly use to find difference between two dates E.g. 01/04/2009 - 03/05/2001 = xxx days instead of writing a function from scratch?
-
July 26th, 2010, 03:57 PM
#4
Re: Manipulating Date and Time
There may be libraries out there which can do it (Boost.Date_Time?), but writing a function would be a good exercise and not that difficult in this case.
-
July 26th, 2010, 04:00 PM
#5
Re: Manipulating Date and Time
This is COleDateTime you could parse the dates with and find the time span between the ones.
Best regards,
Igor
-
July 26th, 2010, 04:07 PM
#6
Re: Manipulating Date and Time
Originally Posted by Lindley
There may be libraries out there which can do it (Boost.Date_Time?), but writing a function would be a good exercise and not that difficult in this case.
I am not very familiar with Boost so I will have to dig into it. I was really thinking there must be some popular library function to do this kind of mundane task.
I am going to take a look at Igor's idea.
----------------------------------------------------
Update:
Thanks Igor. It works! But Lindley I appreciate your idea of taking a look at the Boost function as well.
Last edited by Learned; July 26th, 2010 at 04:18 PM.
-
July 26th, 2010, 09:52 PM
#7
Re: Manipulating Date and Time
If you want to get a span of dates you might also have to learn how to use:
COleDateTimeSpan( );
Rate this post if it helped you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|