AutoHotkey Community

It is currently May 25th, 2012, 12:52 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 31 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: July 25th, 2007, 11:05 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Dea Friends, :)

This is what I have got:

Code:
Begin  := "20050407041630" ; April,  7 2005  4:16:30 AM
End    := "20070725120000" ; July , 25 2007 12:00:00 PM

End -= %Begin%, Seconds

MsgBox, % gft( End )

gft(s) {
; Titan : http://www.autohotkey.com/forum/viewtopic.php?p=93288#93288
   w = day.hour.minute.second
   loop parse, w, .
      s -= (t := s // (x := 60 ** (e := 4 - a_index) - 129600 * (e = 3))) * x
      , t ? m .= t . " " . a_loopfield . chr(115 * (t != 1)) . chr(32 * !!e)
   return m ? m : "0 seconds"
}


gft() returns the age as: 839 days 7 hours 43 minutes 30 seconds

My Requirement: I need an Age() function that will accept two DateTime Stamps as parameters and return me the Age as a valid DateTime Stamp

  • I need an extension of gft() to calculate age, so I can read the result as: 2 years 3 months 18 days 7 hours 43 minutes 30 seconds
  • Even better, I need the function to return me the age as a DateTime Stamp like: 00020318074330
  • Since FormatTime will not work with any date prior to January 1, 1601 , the first number of the DateTime Stamp should be between 2 and 9.
  • Calling Age( "20050407041630", "20070725120000" ) should return me 90020318074330 which I can delimit as per my requirement like example:
    Code:
    Age=90020318074330
    FormatTime, Time, %Age%, yy-MM-dd|H:m:s
    MsgBox, %Time% ; ; will be 02-03-18|7:43:30
  • I am not worried about the code size but the function needs to be really fast as the calling script might call it between 9^2 and 9^9 times


Please help.

:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 25th, 2007, 2:20 pm 
You know that beyond the day (or week) the time units are quite fuzzy: a month and a year don't have a fixed number of seconds in them...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 25th, 2007, 2:43 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Helpy wrote:
You know that beyond the day (or week) the time units are quite fuzzy: a month and a year don't have a fixed number of seconds in them...


Yes.. I am aware of it.
I have mentioned that I am not worried about code size .. only speed!
I not able to think anything more than a loop. :(

I need a method to compute this really fast!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 25th, 2007, 3:03 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
Have you tried searching? There was a similar thread not so long ago.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 25th, 2007, 3:45 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Titan wrote:
There was a similar thread not so long ago.


I missed it.. Thanks. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 25th, 2007, 5:28 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
I am not able to produce any useful code! :(


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 25th, 2007, 5:48 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
There are a million different ways to do this, here's one example:

Code:
d := age(20050407041630, 20070725120000)
FormatTime, t, %d%, yy-MM-dd|H:m:s
MsgBox, %t%

age(s, e) {
   e -= s, s
   d = 2000
   d += e, s
   Return, d
}


For some reason it gives 4 months and 19 days.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 25th, 2007, 6:54 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Titan wrote:
here's one example:


I am have been trying on similar lines ... The leap year between the start date and end date ( if any ) is creating the difference, I guess.

Please post if you find a way to get accurate results.

Thanks :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 25th, 2007, 7:30 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
This is what I have:

Code:
Age := Age( "20050407041630", "20070725120000" )
FormatTime, str, %Age%, yy-MM-dd|HH:mm:ss
MsgBox, %str%

Age( sTS="", eTS="" ) {
 fyear := "90000101"
 eTS   -= %sTS%, S
 fyear += %eTS%, S
 fyear += -33  , D
Return fyear
}


Since fyear is 1-1-9000 I have to deduct 31 days ( for the month of Jan ) to get the correct number of months.

But it varies between -31,-32 and -33 :?: which I think is due to Leap years occurring between the begin date and end date ..

Any ideas ? :roll:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 25th, 2007, 8:31 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
I have to forget about returning the value as a valid timestamp. It is impossible! :shock:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 25th, 2007, 10:20 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
Skan wrote:
I have to forget about returning the value as a valid timestamp. It is impossible!
What makes you so sure?

Code:
MsgBox, % age(20050407041630, 20070725120000)

age(s, e) {
   f = %A_FormatInteger%
   SetFormat, Float, 02.0
   StringSplit, s, s
   Loop, Parse, e
      If A_Index & 1
         t := A_LoopField, d := s%A_Index%
      Else {
         t .= A_LoopField, d .= s%A_Index%, r := t - d + 0.0
         If r < 0
         {
            StringTrimRight, v, v, 2
            v .= l - 1.0, r += 60
         }
         v .= l := r
      }
   SetFormat, Float, %f%
   Return, v
}

That's not the full code obviously, you need to add additional offsets etc.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2007, 12:17 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
The time difference is not well defined in this form. For example, what answer do you expect for a time difference between January 31 and March 1? It is 29 days (30 in leap years), but how many months does it mean? If you say one month, than how many more days? It depends on the length of the month you expect. You cannot count the days from the same date in the next month as in the starting month, because it does not always exist (no February 31).

Even if the answer is in years, days, etc., we still have difficulties. From March 1 to the next year's February 29 it is 365 days. Do you want to say the difference is one year? One could argue that 1 year difference should be till the next March 1, and the answer should be 365 days, which sounds funny.

It is very hard to measure differences in units of changing length (month, year).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2007, 1:42 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
Usually when people talk bout how many years old something is, they mean how many "birthdays" it had. (Special handling needed for Feb 29). Months often just mean 30 days. But it really wouldn't make sense to mix the two. :?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2007, 9:12 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Titan wrote:
Skan wrote:
I have to forget about returning the value as a valid timestamp. It is impossible!
What makes you so sure?


The age between A_Now and A_Now + 1 Second will yield 00000000000001 which is not a valid DateTime stamp.

I have just been here. Will try your code.

:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2007, 9:17 am 
Quote:
Usually when people talk bout how many years old something is, they mean how many "birthdays" it had
I guess Skan is looking for a YourLive_TickCount, right?


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 31 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: mc-lemons, Tegno, Yahoo [Bot] and 16 guests


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

Search for:
Powered by phpBB® Forum Software © phpBB Group