Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Compare filetime and systemtime

Posted on 1999-07-13
12
Medium Priority
?
2,184 Views
Last Modified: 2012-05-04
I have a filetime and want to compare that to the (systemtime - 7 days) and see which one is the oldest. How do I do that ?

Thanks!
0
Comment
Question by:bert1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
12 Comments
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1199921
You can use difftime() to calculate the difference (in seconds) between two time_t values.
There are no standards on obtaining the file time, so we'll need to know the OS and compiler you're targetting/using.
0
 

Author Comment

by:bert1
ID: 1199922
Im using Borland C++ 5.02.
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1199923
Then you can use getftime() to obtain the file time:

#include <stdio.h>
#include <io.h>
#include <time.h>
#include <dos.h>
#include <conio.h>

int main(void)
{
   time_t now;
   FILE *stream;
   struct ftime ft;

   clrscr();

   if ((stream = fopen("TEST.$$$",
        "rt")) == NULL)
   {
      fprintf(stderr, "Cannot open file.\n");
      return 1;
   }

   getftime(fileno(stream), &ft);

   now = time(NULL);  /* Gets system
                           time */

   printf("The difference is: %f seconds\n",difftime(now, ft.time));
   getch();

   fclose(stream);
   return 0;
   return 0;
}

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bert1
ID: 1199924
I have used

GetFileTime( hFile, &CreationTime, &LastAccessTime, &LastWriteTime );

to get the filetime ... how do I compare that to the SYSTEMTIME - 7 days ??

 


0
 

Author Comment

by:bert1
ID: 1199925
I want to subtract 7 days from the system time!

//bert1
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1199926
7 days is 7 * 24 * 60 * 60 =  604800 seconds
if(difftime(now, ft.time) > 604800)
  printf("The file is more then 7 days old");

0
 

Author Comment

by:bert1
ID: 1199927
Im using GetFileTime and SystemTimeToFileTime (winAPI). Not dos!

And I want to subtract a value from the filetime (created) ... -> I need to convert filetime to large integer ... and then subtract , but how do I convert it to large integer?

GetFileTime( hFile, &CreationTime, &LastAccessTime, &LastWriteTime )
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1199928
Actually you are too late with that infornation. Your Q stated that you wanted to compare a file time with the system time. When I asked about what OS and compiler you only stated you were using BC5, not that you would insist upon using Win API. Please be more specific about that in the future!

I suspect you can simply cast the FILETIME struct to a LARGE_INTEGER, they have the same layout.

0
 

Author Comment

by:bert1
ID: 1199929
Im sorry for not being that detailed ... Im new to C++ :-\
I can give you the points ... for the last comment ...
0
 
LVL 7

Accepted Solution

by:
KangaRoo earned 80 total points
ID: 1199930
No problem,
Windows is the major OS, but would we always give Windows answers, this would be incorrect for other OS's.
Secondly, C and C++ have a background in being platform independent, so using a platform independent solution often has privilige.

Did you resolve the question then?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1199931
Kangroo is right.  He put a lot of effort into this question and it was all wasted because you didn't provide all the necessary information.  This is the C++ topic area, not the windows topic area.  A C++ solution, like he offered, is appropriate.  To later require a windows solution is unfair.

Anyways you can convert a FILETIME  to a 64 bit value using

int64 Time = (FT.dwHighDateTime << 32) +  FT.dwLowDateTime;
0
 
LVL 22

Expert Comment

by:nietod
ID: 1199932
opps.  Sorry for my comment at this time.  I was trying to post if for a while, but the page would not accept it.  Now it is clearly out of place.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question