The process of doing the calendar is fairly simple. If you are going to do the date and
time of files, you may need the APIs, although you can strip the information out of a
capture of the command line DIR instruction.
Most dates here in the States are written mm/dd/yyyy. I recall from years ago that the
date elsewhere may be yyyy/mm/dd or even dd/mm/yyyy. You may also have a case
were the year is only two digits. Because of these variations, you may have to either
get clarification of the date being checked for, or shuffle the entries for each about until
you have them where dd is the day of the month, mm is the month of the year, and yy is
the year itself. Here I am assuming that dd, mm, and yy are integers.
With FileTime, you may also want to work down into the hh:mm:ss level as well. That
is easy enough to do, but since you are then going to have to multiply the daycount by
24*60*60 to get to the second level, you will have to build the result up as a quad, not just
as a long. Turns out there are 86,400 seconds in a single day. Oh, and since we are already
using mm for the month, we will use mt for the minute while hh is the hour and ss is the
second.
Let's assume you want it to the second, meaning a quad output, Now it's late, and I don't
want to spend the night on this, so I will provide just an outline. We are going to use dtc
as our DateTimeCount accumulator.
Code: Select all
mm.l=val(a$) ; a$ holds the date and time
a.i=FindString(a$,"/")
dd.i=Val(Mid(a$,a+1))
a=FindString(a$,"/",a+1)
a$=Mid(a$,a+1)
a=FindString(a$," ")
yy.i=Val(left(a$,a-1))
hh.i=Val(Mid(a$,a+1))
a=FindString(a$,":",a)
mt.i=val(Mid(a$,a+1))
a=FindString(a$,":",a+1)
ss.i=Val(Mid(a$,a+1))
If mm > dd and mm>yy ;apparently the provided date was in yyyy/mm/dd order
a=mm ;this will be the year
mm=dd ;this is now the month
dd=yy ;this is now the day
yy=a ;now we set the year
EndIf
dtc.q=dd
If mm<3 ;leap year not an issue if this is months January or February
ElseIf Mod(yy,400)=0
dtc+1
ElseIf Mod(yy,100)=0
ElseIf Mod(yy,4)=0
dtc+1
EndIf
Select Case mm
Case 2
dtc+31
Case 3
dtc+59
Case 4
dtc+90
Case 5
dtc+120
Case 6
dtc+151
Case 7
dtc+181
Case 8
dtc+212
Case 9
dtc+243
Case 10
dtc+273
Case 11
dtc+304
Case 12
dtc+334
End Select
dtc+Int(yy*365.2425) ;at this point you have the daycount
dtc*24
dtc+hh
If hh<12 and FindString(a$,"p")>0
dtc+12
EndIf
dtc*60+mt
dtc*60+ss ;at this point you have your datetimecount to the second
I haven't tested the above code in PureBasic, and am a bit concerned that the
Mod() function specifiies it works with floats or doubles, and I am using integers.
If that doesn't work, I could write my own iMod() function to do the job.