CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2009
    Location
    NY, USA
    Posts
    191

    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?

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Manipulating Date and Time

    Read the line and after that, cut it up in parts.

  3. #3
    Join Date
    Oct 2009
    Location
    NY, USA
    Posts
    191

    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?

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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.

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    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

  6. #6
    Join Date
    Oct 2009
    Location
    NY, USA
    Posts
    191

    Re: Manipulating Date and Time

    Quote Originally Posted by Lindley View Post
    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.

  7. #7
    Join Date
    Jun 2004
    Posts
    1,352

    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
  •  





Click Here to Expand Forum to Full Width

Featured