CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2000
    Posts
    81

    filetime systemtime and duration

    Hello,

    I need the day-duration from a file. How long exists the file in days. I get the filetime I can convert it into a systemtime. But I need the duration in days. I don't like to calculate it alone. Now my question. Does any function exist how I can resolve this problem?


  2. #2
    Join Date
    Nov 2001
    Location
    London. England
    Posts
    114

    Re: filetime systemtime and duration

    Hello,

    If you have the the file time as either a SYSTEMTIME or a FILETIME you can use the following code


    CTimeSpan ts = CTime::GetCurrentTime() - file_time;
    int days=ts.GetDays() ;




    Regards

    Tony


  3. #3
    Join Date
    Aug 2000
    Posts
    81

    Re: filetime systemtime and duration

    Thanks a lot.

    If you know another class as the CTimeSpan it would be helpfully. Because I can't use MFC. Exist a WIN API function?



  4. #4
    Join Date
    Nov 2001
    Location
    London. England
    Posts
    114

    Re: filetime systemtime and duration

    Hello

    OK, try this. You need to start with a FILETIME.


    SYSTEMTIME systime ;
    FILETIME now ;
    GetSystemTime(&systime) ;
    SystemTimeToFileTime(&systime, &now) ;

    LONGLONG interval=((LARGE_INTEGER *)&now)->QuadPart - ((LARGE_INTEGER *)&file_time)->QuadPart;
    interval/=10000000 ; // file time is 100-nanosecond intervals

    int days=(int)(interval/(24*3600)) ;




    Regards

    Tony


  5. #5
    Join Date
    Apr 2000
    Location
    Switzerland
    Posts
    944

    Re: filetime systemtime and duration


    #include "stats.h"
    // if you have the 2 FILETIMES we can do
    __int64 iFile = INT64_FROM_FILETIME(file);
    __int64 iToday = INT64_FROM_FILETIME(today);
    __int64 iDiff = iToday - iFile;
    // That tells us how many times 100 nanosecs there are
    long lDays = iDiff / 864000000000; //100 nanosecs in a day





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