It is currently Tue Feb 25, 2020 2:43 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Compare Dates?
PostPosted: Sat Dec 24, 2005 3:52 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Apr 21, 2004 7:12 pm
Posts: 731
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.

_________________
~I see one problem with your reasoning: the fact is thats not a chicken~


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Dec 24, 2005 4:16 pm 
Offline
Administrator
Administrator

Joined: Wed Apr 23, 2003 7:57 pm
Posts: 1321
Location: Belgium
Quick one, not tested
Code:
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 )

_________________
Berikco

http://www.vispluk.be


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Dec 24, 2005 7:57 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Apr 21, 2004 7:12 pm
Posts: 731
Yeah, it works for pretty well. Howeverwhen I compare 10/07/05 00:00:00 to Date() I end up with 17 days - is that right? Surely it should be 13?

_________________
~I see one problem with your reasoning: the fact is thats not a chicken~


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Dec 24, 2005 11:28 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Sep 24, 2005 2:08 pm
Posts: 997
then, just remove 4 days from the output :D

I also tried it returns really a bigger number than it should...


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Dec 25, 2005 12:06 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Apr 21, 2004 7:12 pm
Posts: 731
You have to edit it for the date I specified :D

_________________
~I see one problem with your reasoning: the fact is thats not a chicken~


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Dec 25, 2005 1:08 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
> not tested

Hehe, it doesn't work at all. It's Christmas Day here, but when I test Christmas Eve...

Code:
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 )

...it says it's 0 Year / 01 Month / 02 Day 11 hour 05 min 05 sec away. :twisted:

_________________
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Dec 25, 2005 2:00 am 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3115
Location: United Kingdom
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...

Code:
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


Pass the date difference (futuredate-pastdate) into nicetime(), you will get a CORRECT string back in return.

Merry Christmas!


-Anthony

_________________
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Dec 25, 2005 10:50 am 
Offline
Addict
Addict
User avatar

Joined: Sat Sep 24, 2005 2:08 pm
Posts: 997
That is really a good functioning one, thanks doubledutch!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 26, 2005 12:45 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3115
Location: United Kingdom
NP, glad to help. :)

_________________
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 26, 2005 2:09 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Apr 21, 2004 7:12 pm
Posts: 731
Thanks :D

_________________
~I see one problem with your reasoning: the fact is thats not a chicken~


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye