Compare Dates?
-
- Enthusiast
- Posts: 731
- Joined: Wed Apr 21, 2004 7:12 pm
Compare Dates?
Is there a way to work out the number of Years, Months, Days, Hours, Minutes and Seconds between two given dates.
For example
10/05/2005
And right now.
For example
10/05/2005
And right now.
~I see one problem with your reasoning: the fact is thats not a chicken~
Quick one, not tested
Code: Select all
OldDate = Date(1999, 5, 4, 8, 32, 23)
Difference = Date() - OldDate
Debug Str(Year(Difference) - 1970) + " Year / "+ FormatDate("%mm Month / %dd Day %hh hour %ii min %ss sec", Difference )
-
- Enthusiast
- Posts: 731
- Joined: Wed Apr 21, 2004 7:12 pm
-
- Enthusiast
- Posts: 731
- Joined: Wed Apr 21, 2004 7:12 pm
> not tested
Hehe, it doesn't work at all. It's Christmas Day here, but when I test Christmas Eve...
...it says it's 0 Year / 01 Month / 02 Day 11 hour 05 min 05 sec away.
Hehe, it doesn't work at all. It's Christmas Day here, but when I test Christmas Eve...
Code: Select all
OldDate = Date(2005, 12, 24, 0, 0, 0)
Difference = Date() - OldDate
Debug Str(Year(Difference) - 1970) + " Year / "+ FormatDate("%mm Month / %dd Day %hh hour %ii min %ss sec", Difference )
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
- DoubleDutch
- Addict
- Posts: 3219
- Joined: Thu Aug 07, 2003 7:01 pm
- Location: United Kingdom
- Contact:
Have you all been at the booze already - your processing it thru a date function... Think about it!
These procedures will work it out nicely for you...
Pass the date difference (futuredate-pastdate) into nicetime(), you will get a CORRECT string back in return.
Merry Christmas!
-Anthony
These procedures will work it out nicely for you...
Code: Select all
Procedure.s AddNumberS(string$,number,ident$)
result$=string$
If number<>0
result$+" "+Str(number)+" "+ident$
If number<>1
result$+"s"
EndIf
EndIf
ProcedureReturn result$
EndProcedure
Procedure.s NiceTime(seconds)
result$=""
Weeks=seconds/604800
seconds=seconds%604800
result$=AddNumberS(result$,Weeks,"week")
Days=seconds/86400
seconds=seconds%86400
result$=AddNumberS(result$,Days,"day")
Hours=seconds/3600
seconds=seconds%3600
result$=AddNumberS(result$,Hours,"hour")
Minutes=seconds/60
seconds=seconds%60
result$=AddNumberS(result$,Minutes,"minute")
result$=AddNumberS(result$,seconds,"second")
If result$=""
result$=" just now "
Else
result$+" "
EndIf
result$=Right(result$,Len(result$)-1)
ProcedureReturn result$
EndProcedure
Merry Christmas!
-Anthony
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
https://reportcomplete.com <- School end of term reports system
- DoubleDutch
- Addict
- Posts: 3219
- Joined: Thu Aug 07, 2003 7:01 pm
- Location: United Kingdom
- Contact:
NP, glad to help.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
https://reportcomplete.com <- School end of term reports system
-
- Enthusiast
- Posts: 731
- Joined: Wed Apr 21, 2004 7:12 pm