Page 1 of 2 12>
Topic Options
#50107 - 2000-05-31 09:20 AM Handling dates
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 Administrator Offline
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
#50109 - 2000-05-31 01:11 PM Re: Handling dates
BoxKite Offline
Da Box
*****

Registered: 2000-05-17
Posts: 282
Loc: Vacaville,CA,USA
AAAAAAAAAHHHHHHH.........................
_________________________
Box
FACTA NON VERBA

Top
#50110 - 2000-05-31 01:53 PM Re: Handling dates
BoxKite Offline
Da Box
*****

Registered: 2000-05-17
Posts: 282
Loc: Vacaville,CA,USA
Hail Jochen. We who about to die salute you. I once had to do this for my company using C++. I had to consider: Leap year or not; month is 31/30/28 days; if January back to December. Luckily, my company paid for my stay in the hospital (mental:eek .

------------------
BoxKite
FACTA NON VERBA

_________________________
Box
FACTA NON VERBA

Top
#50111 - 2000-05-31 02:08 PM Re: Handling dates
Jochen Administrator Offline
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 Offline
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
#50113 - 2000-06-13 01:13 PM Re: Handling dates
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
LD,James,Shawn!!!

i'm alive ... just back from a short holiday
(my wife locked my Computers and throwed the key away )....

Ok, here is a short status for this topic :

-> script is not now finished; about 60%
-> Shawn : i will use some of Your code (b.t.w: wrong variable name - 'julian_runsum'!..it have to be: 'gregorian_runsum' explanation will follow)
-> the problem is; with the 'pope_gregor_calendar' we had a new rule invented back in 1582 :
-> an additional leap year every 400 years to near the 'sun_revolution_drift' to 1 day in 3300 years....


So the 'not perfect - but running' code will be hopefully finished in about and during next week ... (doesn't have that much spare time , cj)

Cheers Jochen

_________________________



Top
#50114 - 2000-06-14 02:49 AM Re: Handling dates
BoxKite Offline
Da Box
*****

Registered: 2000-05-17
Posts: 282
Loc: Vacaville,CA,USA
I think Lord Alfred Tennyson said it best when he wrote;

Half a league, Half a league, Half a league onward,
All in the valley of Death Rode the six hundred.…………………………….."Forward, the Light Brigade!…………………………….. Honor the charge they made, Honor the Light Brigade, Noble six hundred.


_________________________
Box
FACTA NON VERBA

Top
#50115 - 2000-06-14 05:59 PM Re: Handling dates
Shawn Administrator Offline
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
#50116 - 2000-06-15 04:48 PM Re: Handling dates
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Shawn,

i am actually pressing [for my night shift]
thanks brother....

by the way whats the exact meaning of 'succumbed' ....
'Are You threatening me'? as beavis would say.

Cheers

P.S.: i managed to run Your Code [problems with cut/paste], it tells me that i am right today [06/16] 11307 Days old
so i think the leap Year calculation works perfect .... [*GREAT*]
Can anybody guess my Birthday with this number of days given [just to confirm correctness of Script]???

[This message has been edited by jpols (edited 16 June 2000).]

_________________________



Top
#50117 - 2000-06-16 11:01 PM Re: Handling dates
BoxKite Offline
Da Box
*****

Registered: 2000-05-17
Posts: 282
Loc: Vacaville,CA,USA
Do I get a Cuzillion Smack-a-roos if I guess right?

Dec 15

_________________________
Box
FACTA NON VERBA

Top
#50118 - 2000-06-19 02:16 PM Re: Handling dates
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Jochen:

How about 02-JUL-1969 ?

Shawn.

Top
#50119 - 2000-06-19 07:18 PM Re: Handling dates
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Shawn,
not bad .... just one day less [age] and it is right .....Update: 03-Jul-1969 --Yeahh,
it was the 'Summer of '69'
James,
not even warm in the region of December!!


Hope You don't get this date by ecexuting Your snippet [if yes, we have a problem in leap calc]

so long partner
J. Wayne

p.s.: if i ever finish bringing your code and mine into a working form we can calculate the 11307 days back from the 06/16/00

[This message has been edited by jpols (edited 19 June 2000).]

[This message has been edited by jpols (edited 19 June 2000).]

_________________________



Top
#50120 - 2000-06-19 07:51 PM Re: Handling dates
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Jochen:

code:

_|/
." ".
__ /(o)-(o)\
/_)|] / |
|_)|] '- |
\_)|] '.___.' / |\/|_
| / \ \_/ / _| '/
|--\ '.___.' \ ) /
\ \_/\__/\__ |==|
\ \ /\ /\ `\ | |
\ \\// \| |
`\ /\ | / |
; | | |\____/
| | | | jgs

CHEERS!


So what's the status on that date minus 14 days script my man ?

Shawn.

[This message has been edited by Shawn (edited 19 June 2000).]

Top
#50121 - 2000-06-19 07:52 PM Re: Handling dates
BoxKite Offline
Da Box
*****

Registered: 2000-05-17
Posts: 282
Loc: Vacaville,CA,USA
Well I didn't need a Cuzillion Smack-a-roos anyway.
_________________________
Box
FACTA NON VERBA

Top
#50122 - 2000-06-19 08:24 PM Re: Handling dates
Shawn Administrator Offline
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
#50123 - 2000-06-21 12:09 AM Re: Handling dates
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
shawn,
right , but we have to think BIG!
I prefer this sript to be Y10K compliant....
[Excel 2000 is NOT ]

yet more gray hair to come...

Confucius

[This message has been edited by jpols (edited 20 June 2000).]

_________________________



Top
#50124 - 2000-06-20 03:23 PM Re: Handling dates
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Jochen:

With your permission, may I post my "creative" and "off-the-wall" solution to this date problem ?

Shawn.

Top
#50125 - 2000-06-20 05:15 PM Re: Handling dates
Jochen Administrator Offline
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
#50126 - 2000-06-20 05:25 PM Re: Handling dates
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Jochen:

Thanks duke !

Believe me, this solution will in no way jeopardize any of your work !

But before I post, will you answer my post re: Starters->Proper procedure for posting code.

Shawn.

Top
Page 1 of 2 12>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 366 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.102 seconds in which 0.054 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org