#50107 - 2000-05-31 09:20 AM
Handling dates
|
Anonymous
Anonymous
Unregistered
|
Has anyone got a script that can get the current date and then find out what it was 14 days ago?
|
Top
|
|
|
|
#50108 - 2000-06-01 12:38 AM
Re: Handling dates
|
Jochen
KiX Supporter
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
LD,just writing it as i am replying.... not nice but working: code:
have a little problem with calculation (Y2k) will post the code as soon i am finished it Jochen
[This message has been edited by jpols (edited 31 May 2000).]
_________________________
|
Top
|
|
|
|
#50111 - 2000-05-31 02:08 PM
Re: Handling dates
|
Jochen
KiX Supporter
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
James,got it nearly.... problem now is calculating with leap Years;@ydayno back to @mdayno;and last not least Year-hops... it is now 9:12pm here in Germany (21:09 GMT +1:00) and i am about to go MAAAAAAAAAAAAAAD Jochen [This message has been edited by jpols (edited 31 May 2000).]
_________________________
|
Top
|
|
|
|
#50112 - 2000-06-01 10:54 AM
Re: Handling dates
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
Gang:Here's a script that calculates the number of days between two dates. Maybe there's some snippets here that someone can use ! There must be a better ( faster ) way of doing this though ? Help me - but please don't make me look like an idiot for submitting this monster ! Plus - I think the code here has a minor ( one or two day diff) bug in it. Cudo's and admiration to anyone who can figure it out !
code:
; Calculate days between dates ... break on if $pipe redirectoutput ( $pipe ) endif
dim $julian_runsum[13]
$julian_runsum[00] = 0 $julian_runsum[01] = 31 $julian_runsum[02] = 59 $julian_runsum[03] = 90 $julian_runsum[04] = 120 $julian_runsum[05] = 151 $julian_runsum[06] = 181 $julian_runsum[07] = 212 $julian_runsum[08] = 243 $julian_runsum[09] = 273 $julian_runsum[10] = 304 $julian_runsum[11] = 334 $julian_runsum[12] = 365
?"Enter date [YYYY/MM/DD] : " gets $date1 ?"Enter date [YYYY/MM/DD] : " gets $date2
$y1 = val(substr($date1,1,4)) $m1 = val(substr($date1,6,2)) $d1 = val(substr($date1,9,2))
$y2 = val(substr($date2,1,4)) $m2 = val(substr($date2,6,2)) $d2 = val(substr($date2,9,2))
gosub the_days_between
?"Days between = $days"
exit
;---------------- :the_days_between ;---------------- $julian_y = $y1 $julian_m = $m1 $julian_d = $d1
gosub calc_julian
$t1 = $julian_date
$julian_y = $y2 $julian_m = $m2 $julian_d = $d2
gosub calc_julian
$t2 = $julian_date
if ( $y1 <> $y2 ) if ( $y1 > $y2 )
$max = $y1 $min = $y2
$julian_y = $y2 $julian_m = 12 $julian_d = 31
gosub calc_julian
$t2 = $julian_date - $t2
else
$max = $y2 $min = $y1
$julian_y = $y1 $julian_m = 12 $julian_d = 31
gosub calc_julian
$t1 = $julian_date - $t1
endif
$i = $max
while $i > ( $min + 1 )
$leapyear_y = $i
gosub isleapyear
$years = $years + 365 + $leapyear
$i = $i - 1
loop
else
$days = $t1 - $t2
return
endif
$days = $t1 + $t2 + $years
return
;----------- :calc_julian ;-----------
; input : date as $julian_y $julian_m $julian_d ; output : days as $julian_date
$total = $julian_runsum [ $julian_m - 1 ] + $julian_d
if ( $julian_m > 2 )
$leapyear_y = $julian_y
gosub isleapyear
$total = $total + $leapyear
endif
$julian_date = $total
return
;---------- :isleapyear ;----------
if (( $leapyear_y * 4096 / 400 ) & (4095) ) = 0
$leapyear = 1
else
if (( $leapyear_y * 4096 / 4 ) & (4095) ) = 0 and (( $leapyear_y * 4096 / 100 ) & (4095) ) <> 0
$leapyear = 1
else
$leapyear = 0
endif
endif
return
Shawn.
[This message has been edited by Shawn (edited 08 June 2000).]
|
Top
|
|
|
|
#50115 - 2000-06-14 05:59 PM
Re: Handling dates
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
I think Jochen may have already succumbed !code:
___ |KIX| __| |__ ##### ##--| _ _ |--> | o o | \ V / | O | \ / /-------\ ---OOO--------OOO------ Jochen - peeking out from behind his cubicle !
KEEP PRESSING ONWARD MY BROTHER ! Shawn. [This message has been edited by Shawn (edited 14 June 2000).]
|
Top
|
|
|
|
#50122 - 2000-06-19 08:24 PM
Re: Handling dates
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
Jochen:Actually, to be fair to Box, I used Excel to calculate the date. Just plug in the two dates with date format, then subtract them into a numeric cell, and you'll get the official "Microsoft supported" answer. I was using this method to verify my code above, that how I know there's still a bug in there. It's weird, no matter how far back you go, it's still one or two days off ? You should use this to verify your script. I think the leapyear function is cool ! Try running it with the following drivers: code:
$year = 0 while $year < 2001 $leapyear_y = $year gosub isleapyear if $leapyear ?"$year is leapyear" endif $year = $year + 100 loop
or: code:
$year = 1899 while $year < 2001 $leapyear_y = $year gosub isleapyear if $leapyear ?"$year is leapyear" endif $year = $year + 1 loop
Shawn.
|
Top
|
|
|
|
#50125 - 2000-06-20 05:15 PM
Re: Handling dates
|
Jochen
KiX Supporter
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
Shawn,yep brother, go ahead ...(created excel-sheet in 2 minutes that did it perfect) i am half-way through the code but it is not yet publishable [work is getting me every time i have 2 minutes to edit the script;ok,ok i won't get paid for that but it's getting personal] i would appreciate any '2-line'-Solution... didn't even get another batch running i promised Mark [starters->he did the script already] just a simple 'for /f ....etc. do ...'-line with a simple grep command in it ...[nobody knewed the synthax and all experemiments failed so far] Cheers Jochen [This message has been edited by jpols (edited 20 June 2000).]
_________________________
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 255 anonymous users online.
|
|
|