Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

ANN: subtract-dates

 [1/10] from: rebol-list2::seznam::cz at: 6-Jun-2003 16:19


Librarian comment

In recent versions of REBOL, use difference to subtract two dates.

Hello rebol-list, is there any simple way how to subtract 2 dates? I had to write this function: subtract-dates: func[ "Returns the second date subtracted from the first in time! datatype." end [date!] start [date!] /local time days ][ if end < start [return negate subtract-dates end start] time: (either none? end/time [0:0][end/time]) - (either none? start/time [0:0][start/time]) either 0 < days: end/day - start/day [(days * 24:00) + time][ time ] ] ;so for example this will return time since 1-1-2003: subtract-dates now 1-1-2003 -- Best regards, rebOldes mailto:[rebol-list2--seznam--cz]

 [2/10] from: nitsch-lists:netcologne at: 7-Jun-2003 11:48


>> difference 7-jun-2003/23:59 8-jun-2003/00:01
== -0:02 -volker rebOldes wrote:

 [3/10] from: Al:Bri:xtra at: 7-Jun-2003 22:20


rebOldes wrote:
> is there any simple way how to subtract 2 dates? >> now
== 7-Jun-2003/22:18:25+12:00
>> now - 10
== 28-May-2003/22:18:28+12:00
>> x: now - 10
== 28-May-2003/22:18:54+12:00
>> now - x
== 10 Andrew J Martin Or perhaps I've misunderstood? :-/ ICQ: 26227169 http://www.rebol.it/Valley/ http://Valley.150m.com/

 [4/10] from: lmecir:mbox:vol:cz at: 7-Jun-2003 20:07


> is there any simple way how to subtract 2 dates? > I had to write this function: > > subtract-dates: func[ > "Returns the second date subtracted from the first in time!
datatype."
> end [date!] start [date!] > /local time days > ][ > if end < start [return negate subtract-dates end start] > time: (either none? end/time [0:0][end/time]) - (either none?
start/time [0:0][start/time])
> either 0 < days: end/day - start/day [(days * 24:00) + time][
time ]
> ] > > ;so for example this will return time since 1-1-2003: > subtract-dates now 1-1-2003 > > -- > Best regards, > rebOldes mailto:[rebol-list2--seznam--cz]
I am using a function, that doesn't return a time! value for a long time. Is this property of your function intended?
>> subtract-dates 22/4/2003 21/3/2003
== 24:00

 [5/10] from: brett:codeconscious at: 8-Jun-2003 12:05


Hi rebOldes, This is my version, but as Volker has shown it is made redundant by Difference in the latest REBOLs except the latest non-experimental, non-beta View (1.2.1): subtract-datetimes: function [ "Subract one date from another returning time between them." a [date!] b [date!] ] [delta-days delta-hhmmss a-hhmmss b-hhmmss] [ delta-days: subtract a/date b/date a-hhmmss: either a/time [a/time] [00:00:00] b-hhmmss: either b/time [b/time] [00:00:00] return add (multiply 24:00:00 delta-days) (subtract a-hhmmss b-hhmmss) ] Regards, Brett

 [6/10] from: brett:codeconscious at: 8-Jun-2003 12:23


Further to my last post - for fun - a more concise version for View 1.2.1 users: timediff: func [ "Subract one date from another returning time between them." a [date!] b [date!] ] [ add a/date - b/date * 24:00:00 subtract any [a/time 00:00:00] any [b/time 00:00:00] ] --Brett

 [7/10] from: maarten:koopmans:surfnet:nl at: 8-Jun-2003 11:20


Brett Handley wrote:
> Hi rebOldes, > > This is my version, but as Volker has shown it is made redundant by > Difference in the latest REBOLs except the latest non-experimental, non-beta > View (1.2.1): >
Which shows that there is a lot of "little" progress in REBOL. --Maarten

 [8/10] from: rebolek::seznam::cz at: 8-Jun-2003 18:52

=?iso-8859-2?Q?Re=3A=20=5BREBOL=5D=20ANN=3A=20subtract=2Ddates?=


??? what's wrong with
>> now - 1-1-2003
== 158 bye, bolek Dne 6. =E8erven 2003, <[rebol-list--rebol--com]> napsal:
> Hello rebol-list, > is there any simple way how to subtract 2 dates?
<<quoted lines omitted: 17>>
> [rebol-request--rebol--com] with "unsubscribe" in the > subject, without the quotes.
______________________________________________________________________ Reklama: P=F8iprav se na nejp=F8=ED=B9ern=ECj=B9=ED z=E1=BEitek v =BEivot=EC na http://ad2.seznam.cz/redir.cgi?instance=46466%26url=http://www.priserky.cz

 [9/10] from: rebol-list2:seznam:cz at: 8-Jun-2003 21:31

Re: ANN: subtract-dates


Hello Boleslav, Sunday, June 8, 2003, 6:52:03 PM, you wrote: BB> ??? BB> what's wrong with
>>> now - 1-1-2003
BB> == 158 This is number of days! I need to count with bigger precision. That's why subtract-dates returns time! datatype. If you wonder what I'm counting... how much I will pay for my dial-up connection. BB> bye, bolek BB> Dne 6. červen 2003, <[rebol-list--rebol--com]> napsal:
>> Hello rebol-list, >>
<<quoted lines omitted: 24>>
>> >>
BB> ______________________________________________________________________ BB> Reklama: BB> Připrav se na nejpříšernější zážitek v životě na http://ad2.seznam.cz/redir.cgi?instance=46466%26url=http://www.priserky.cz BB> -- BB> To unsubscribe from this list, please send an email to BB> [rebol-request--rebol--com] with "unsubscribe" in the BB> subject, without the quotes. -- Best regards, rebOldes mailto:[oliva--david--seznam--cz]

 [10/10] from: rebol-list2:seznam:cz at: 8-Jun-2003 21:34


Hello Volker, Saturday, June 7, 2003, 11:48:26 AM, you wrote: VN> >> difference 7-jun-2003/23:59 8-jun-2003/00:01 VN> == -0:02 This is very nice, thank you. -- Best regards, rebOldes mailto:[oliva--david--seznam--cz]

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted