Hi all,
2nd week programming and face first into the wall again haha. As always I appreciate any advice or critique.
I have a small c++ program that reads through log files from a program and scans for errors. For the most part it works really well but I'm trying to add functionality and options to the program in terms of date/time selection.
essentially the date and time in the logs is presented like this:
12-Oct-2010
11-Jun-2011
14-Sep-2009
and so on. I was able to calculate the current time and my first option which is (current time - 30) days with this:
int endTime = 0;
endTime = time(NULL);
int startTime = (endTime - ((60*60*24)*30));
this gives me a number of 139128491824 blah blah so on which is fine because its constant, what I'm trying to do is convert the date structure listed above into a comparable number so I can say if
if (endTime >= start time && logTime <= endTime
thats basically the last 30 days (of course I can change it to 1 day 10 days whatever the need).
does anyone have any advice on how to do this? I've tried using swscanf() (its all utf-16 so has to be widestring). The code looks something like this
#include so on so on
int day = 0;
int year = 0;
wchar_t month [4] = {0};
wchar_t* logDate = L"12-Oct-2011";
swscanf(logDate, L"%d-%[^-]s-%d", &day, month, &year);
This almost works in that when I
wprintf ("d", day)
and so on I get the date listed in my *logDate but i'm struggling to comprehend how to make it read for any date in the "00-abc-0000" format (not to mention when i printf (%d, year) it only returns 0 >.< ).
As you can see I'm not really sure how to proceed, if I can get swscanf to read all the possible months I can just say if = oct oct=10 kind of thing and that puts it in the 00.00.0000 time format so I can get the same number.
Am I going about this the wrong way? Is there an easier way to do it? As always thanks for any advice.