Reputation: 3
I have an imput .txt file, which contains a date. The date is in the form DDMONYY, as in 08JUN98 or 16NOV05. I need to compare this date to the creation date of the file, and see which is sooner.
FILETIME seems like the appropriate form, especially since there is a CompareFileTime function. However, I have a problem converting the date into file time.
I can extract the date from the file and convert it into numbers (days 1-31, month 1-12, year 1900-20whatever) so I don't need help with that, but feel free to comment on it anyway.
The real problem is that I can't figure out how to get these values into a FILETIME format. Right now I have them as three different strings(or int's if that helps more) one for day, month and year. If you could help me make the jump from string to FILETIME that would be great.
Or, if there is a completely better way that I missed during my research, please feel free to suggest it.
If you want, I can post what I have, but I don't think it'll help since it's only getting to the string/int's.
if it makes it any clearer, the values I have in my variables at this point, for May 3rd, 2002, would be something along the lines of
string day = "03";
string month ="5";
string year = "2002;
int dayint = 3;
int monthint = 5;
int yearint = 2002;
And I need a way to convert this to a FILETIME
Thanks a bunch.
EDIT:
I'm not sure how I would fill a SYSTEMTIME
structure, or even how to do it for a different time system. So I guess that is more my question.
I should have also mentioned that I only need accuracy of days. Hours and anything smaller aren't really of concern to me.
EDIT2:
I must not have tried giving the SYSTEMTIME
int values, because that seems to work. However, I am running into issues when I try to convert that systemtime to a filetime. It states "Error: no suitable converstion from "SYSTEMTIME" to "const SYSTEMTIME *" exists". I'm not sure how to fix this, since if I define the systime variable as const SYSTEMTIME
I can't assign values to it.
here's the relevant code, if it helps
SYSTEMTIME systime;
LPFILETIME ftime1;
LPFILETIME ftime2;
int dayint=6;
int monthint=12;
int yearint=1989;
systime.wDay = dayint;
systime.wMonth = monthint;
//and so on for year, hour, etc.
SystemTimeToFileTime(systime,ftime1); //This is where the aforementioned error occurs
GetFileTime(filename, NULL, NULL, ftime2); //I'm also not sure about this line... feel free to critique it. I'm only interested in the last written time so I put NULL for the other times... When I check the values for this (in SYSTEMTIME) it only returns 52428, so I don't think this line is working correctly...
CompareFileTime(ftime1,ftime2);
Of course, the values for day, month, year aren't hardcoded in the actual code.
EDIT3:
I have a bad handle....
I'm going to try to fix that.... Thanks for your help Ben Voigt If I can't get it, I guess I'll be back
Upvotes: 0
Views: 3962
Reputation: 283634
You can fill in a SYSTEMTIME
structure and then call SystemTimeToFileTime
You may want to use LocalFileTimeToFileTime
afterwards, depending on whether you want to specify the hours in UTC or local time.
Upvotes: 4