Article View: borland.public.cppbuilder.nativeapi
Article #14009Re: comparing Dates
From: Luiz Rafael Culik Guimaraes
Date: Thu, 04 Sep 2003 16:14
Date: Thu, 04 Sep 2003 16:14
68 lines
2839 bytes
2839 bytes
Bob
>
> >What is the best way to get the smallest date between two SYSTEMTIME
values
>
> What do you mean the "smallest date"? You can get the difference by
> converting to 64bit integers and subtracting (As the SYSTEMTIME help
> suggests) Ah, the word "between" threw me: "get the smallest of two"
Example
iļæ½m using the FindFirstFile()/FindNextFile() api to get the olddest date of
an file with an specific directory
this is my current Routine for acumplish this
static FILETIME GetOldesFile(char * szPath)
{
WIN32_FIND_DATA Lastff32;
HANDLE hLastFind;
FILETIME ftLastWriteTime ={0x99999999,0x9999999}; // <- Set the olddest
file to an future date(year 3059)
FILETIME ft,ft1;
SYSTEMTIME time,time1;
char * szf = (char*)malloc(7);
strcpy(szf,szPath);
strcat(szf,"*.*");
hLastFind = FindFirstFile( szf,&Lastff32 );
if ( hLastFind != INVALID_HANDLE_VALUE )
{
if (Lastff32.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
ftLastWriteTime= Lastff32.ftLastAccessTime;
while ( FindNextFile( hLastFind,&Lastff32 )) {
if (Lastff32.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if( FileTimeToLocalFileTime( &Lastff32.ftLastAccessTime, &ft )
&&
FileTimeToSystemTime( &ft, &time ) &&
FileTimeToLocalFileTime( &ftLastWriteTime, &ft1 ) &&
FileTimeToSystemTime( &ft1, &time1 ) )
if( time.wYear <= time1.wYear )
{
ftLastWriteTime = Lastff32.ftLastAccessTime;
// if (time.wMonth <= time1.wMonth )
}
// ftLastWriteTime = Lastff32.ftLastAccessTime;
}
}
FindClose( hLastFind );
}
free(szf);
return ftLastWriteTime;
}
Regards
Luiz
Technical Details
Message-ID:
<3f5764ed@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3f574a3e$1@newsgroups.borland.com> <asjelv8fq5h0jkedp42auupaqs62b3c3jd@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 10cc67,7bb8b0b789f7aaae X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-09-04 09:22:48 PST From: "Luiz Rafael Culik Guimaraes" <culikr@uol.com.br> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f574a3e$1@newsgroups.borland.com> <asjelv8fq5h0jkedp42auupaqs62b3c3jd@4ax.com> Subject: Re: comparing Dates Date: Thu, 4 Sep 2003 13:14:11 -0300 Lines: 70 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 200.180.162.72 Message-ID: <3f5764ed@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1062692077 200.180.162.72 (4 Sep 2003 09:14:37 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail