Here are two date functions that have been added to FF3 that you will access to once version 3.10 is released.
'--------------------------------------------------------------------------------
' FF_DateAdd
' Add or subtract days from a date
' Valid date format: YYYYMMDD, YYYY-MM-DD, YYYY/MM/DD
'--------------------------------------------------------------------------------
Function FF_DateAdd( ByVal sDate As String, _
ByVal nNumDays As Long _
) As String
Local sTime As SYSTEMTIME
Local fTime As FILETIME
Local nTemp As Quad
sDate = Retain$( sDate, any "0123456789" )
sTime.wYear = Val(Left$(sDate, 4))
sTime.wMonth = Val(Mid$(sDate, 5, 2))
sTime.wDay = Val(Right$(sDate, 2))
SystemTimeToFileTime sTime, fTime
MoveMemory ByVal VarPtr(nTemp), ByVal VarPtr(fTime), ByVal SizeOf(fTime)
' FileTime returns 100's of NANOSECONDS so you have to adjust
' **** IncrValue * 10000000 to convert to Nanoseconds
nTemp = nTemp + (nNumDays * 86400 * 10000000) ' #of seconds per day is 86400
MoveMemory ByVal VarPtr(fTime), ByVal VarPtr(nTemp), ByVal SizeOf(nTemp)
FileTimeToSystemTime fTime, sTime
Function = Format$(sTime.wYear, "0000") & _
Format$(sTime.wMonth, "00") & _
Format$(sTime.wDay, "00")
End Function
'--------------------------------------------------------------------------------
Function FF_DateDiff( ByVal sDate1 As String, _
ByVal sDate2 As String _
) As Long
Local sTime1, sTime2 As SYSTEMTIME
Local fTime1, fTime2 As FILETIME
Local nTemp, nTemp1, nTemp2 As Quad
sDate1 = Retain$( sDate1, Any "0123456789" )
sDate2 = Retain$( sDate2, Any "0123456789" )
sTime1.wYear = Val(Left$(sDate1, 4))
sTime1.wMonth = Val(Mid$(sDate1, 5, 2))
sTime1.wDay = Val(Right$(sDate1, 2))
SystemTimeToFileTime sTime1, fTime1
MoveMemory ByVal VarPtr(nTemp1), ByVal VarPtr(fTime1), ByVal SizeOf(fTime1)
sTime2.wYear = Val(Left$(sDate2, 4))
sTime2.wMonth = Val(Mid$(sDate2, 5, 2))
sTime2.wDay = Val(Right$(sDate2, 2))
SystemTimeToFileTime sTime2, fTime2
MoveMemory ByVal VarPtr(nTemp2), ByVal VarPtr(fTime2), ByVal SizeOf(fTime2)
' The difference is the number of nanoseconds between the
' two dates. Convert to days.
nTemp = (nTemp1 - nTemp2) / (86400 * 10000000)
Function = nTemp
End Function
This is really great Paul. Thank you!!!
I have them now. Why do I need 3.10 ???
Quote from: Peter House on October 15, 2010, 11:40:50 PM
I have them now. Why do I need 3.10 ???
You don't need 3.10. I just meant that the functions will be included int he standard FF3 installation once I finally pop out 3.10.
Paul,
I meant that as a joke.
Apparently it had all the elements of a joke except the humor.
Keep up the good work - I don't need 3.10 but I do look forward to it.
Very nice. Date and Time functions is something that PB never bothered with.
It's been so long since my last burst of programming that I can't remember how to do this...
Is there a way that I can add these 2 functions into FF 3.09?
Thanks,
-John
Depending on how you installed, there is a folder either under the install folder or in your My Documents folder called something like "Code Snippets" You can put them there.
Here are the two functions in a zip. Unpack them into FireFly's codestore. I had put them into the general folder.
..\CodeStore\PowerBASIC\FireFly_Functions\General
Then they are available in the Functions Library (F8).
Thanks for the help! I now have them installed in "General", too!
I'm going to be testing them -- I need to be able to specify a "Remind me" date and time, based on a given date/time, and a specification of weeks, days, hours, and minutes (or a combination).
I need to find out: will this new Date function be able to handle it, if for example, I have a date/time of April 3, 2011 10am, and I need to find the date/time that is 3 Days, 6 Hours, and 45 minutes earlier?
Thanks,
-John
ALSO: I renamed the folder "General" to "_General", so it now appears at the top of the list...
Quote from: John Montenigro on February 02, 2011, 01:37:32 PM
I need to find out: will this new Date function be able to handle it, if for example, I have a date/time of April 3, 2011 10am, and I need to find the date/time that is 3 Days, 6 Hours, and 45 minutes earlier?
Well, in the thread "Date Calculations", I have a function "TimeCalculation" that returns March 31, 2011 at 3:15am. See attachment in first thread.
Rick
Thanks, Richard,
I've d/l'd the files and will try them out over the weekend.
-John