#157549 - 2006-02-21 06:57 PM
Display date last week
|
ledzepe
Fresh Scripter
Registered: 2005-12-06
Posts: 26
|
Hi everybody, I need a script to display the date last week. For example, today is Feb 21 (2006/02/21) and I want to display Feb 14(2006/02/14). I could always subtract the day but what would happen if its the next month?
|
Top
|
|
|
|
#157550 - 2006-02-21 07:14 PM
Re: Display date last week
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
i don't know if this is what you are looking for but maybe it is a start: you will need to install KiXforms first then you can run Calendar
|
Top
|
|
|
|
#157551 - 2006-02-21 07:30 PM
Re: Display date last week
|
Chris S.
MM club member
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
"One second after midnight: " + fnDateDiff(@DATE,1,"s") ? "One second before midnight: " + fnDateDiff(@DATE,-1,"s") ? "Seconds between today and tomorrow: " + fnDateDiff(@DATE,fnDateDiff(@DATE,1,"d"),"s",0) ? "Weeks between today and six days from today: " + fnDateDiff(@DATE,fnDateDiff(@DATE,6,"d"),"w",0) ? "Weeks (fixed) between today and six days from today: " + fnDateDiff(@DATE,fnDateDiff(@DATE,6,"d"),"w",1) ? "Shopping days until my birthday: " + fnDateDiff(@DATE,"2006/04/20","d") ? "Seconds between 1/1/1601 and 1/1/1970: " + fnDateDiff("1601/01/01","1970/01/01","s") ? "Hours between NOW and 9/18/2005 13:00: " + fnDateDiff(@DATE+' '+@TIME,"2005/09/18 13:00:00","h") ? "Hours between 9/18/2005 13:00 and NOW: " + fnDateDiff("2005/09/18 13:00:00",@DATE+' '+@TIME,"h") ? "Yesterday's date: " + fnDateDiff(@DATE,-1,"d") ? "Seconds between midnight and 11:59:59 pm: " + fnDateDiff("00:00:00","23:59:59","s") ? "Seconds between 11:59:59 pm and midnight: " + fnDateDiff("23:59:59","00:00:00","s") ? "Add one minute to midnight: " + fnDateDiff("00:00:00",1,"m",0) ? "VarTypeName of fnDateDiff output: " + VarTypeName(fnDateDiff(@TIME,0,"s")) ? "VarTypeName of @@TIME: " + VarTypeName(@TIME) ? @SERROR ? Get $ Function fnDateDiff($DateTime,Optional $DateOrInterval,$Interval,$Fix) Dim $Date1,$Date2,$jDate[2],$jTime[2],$y,$m,$d,$ss,$mm,$hh,$i $Date1=Split($DateTime," ") If UBound($Date1)>1 Exit 1901 EndIf If UBound($Date1)=0 Select Case InStr($Date1[0],"/") $jDate=Split($Date1[0],"/") Case InStr($Date1[0],":") $jDate=Split("1899/12/30","/") $jTime=Split($Date1[0],":") Case 1 Exit 1901 EndSelect Else If InStr($Date1[0],"/") and InStr($Date1[1],":") $jDate=Split($Date1[0],"/") $jTime=Split($Date1[1],":") Else Exit 1901 EndIf EndIf $y=Val($jDate[0]) If $y=0 Exit 1901 EndIf $m=Val($jDate[1]) If $m<1 or $m>12 Exit 1901 EndIf $d=Val($jDate[2]) If $d<1 or $d>31 Exit 1901 EndIf If $m < 3 $m=$m+12 $y=$y-1 EndIf $jDate = CDbl($d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306) $jTime = CDbl((Val($jTime[0])*3600)+(Val($jTime[1])*60)+Val($jTime[2]))/86400 If $jTime=>1 Exit 1901 EndIf $Date1=CDbl($jDate+$jTime)*86400 If VarType($DateOrInterval) If InStr($DateOrInterval,"/") or InStr($DateOrInterval,":") $Date2=fnDateDiff($DateOrInterval) $fnDateDiff=$Date2-$Date1 Select Case $Interval="s" Case $Interval="m" $fnDateDiff=$fnDateDiff/60 Case $Interval="h" $fnDateDiff=$fnDateDiff/3600 Case $Interval="d" $fnDateDiff=$fnDateDiff/86400 Case $Interval="w" $fnDateDiff=$fnDateDiff/604800 Case 1 Exit 87 EndSelect If $Interval="s" $fnDateDiff=CInt($fnDateDiff) EndIf If $Fix $fnDateDiff=Fix($fnDateDiff) EndIf Else If VarType($DateOrInterval)>5 Exit 87 EndIf Select Case $Interval="s" If VarType($DateOrInterval)>3 Exit 87 EndIf Case $Interval="m" $DateOrInterval=$DateOrInterval*60 Case $Interval="h" $DateOrInterval=$DateOrInterval*3600 Case $Interval="d" $DateOrInterval=$DateOrInterval*86400 Case $Interval="w" $DateOrInterval=$DateOrInterval*604800 Case 1 Exit 87 EndSelect $fnDateDiff=($Date1+$DateOrInterval)/86400 $jTime=$fnDateDiff-Fix($fnDateDiff) $jDate=Fix($fnDateDiff) $y = (100*(((100*($jDate+306)-25)/3652425)-(((100*($jDate+306)-25)/3652425)/4))+ (100*($jDate+306)-25))/36525 $m = (5*(((100*($jDate+306)-25)/3652425)-(((100*($jDate+306)-25)/3652425)/4)+ ($jDate+306)-365*$y-$y/4)+456)/153 $d = (((100*($jDate+306)-25)/3652425)-(((100*($jDate+306)-25)/3652425)/4)+ ($jDate+306)-365*$y-$y/4)-(153*$m-457)/5 If $m>12 $y=$y+1 $m=$m-12 EndIf If Len($y)<4 $ = Execute("For $$i=1 to 4-len($$y) $$y = '0' + $$y Next") EndIf $m = Right("0"+$m,2) $d = Right("0"+$d,2) $ss = CInt(86400.0*$jTime) $mm=$ss/60 $ss=$ss mod 60 $hh=$mm/60 $mm=$mm mod 60 $jDate=Iif($y,''+$y+'/'+$m+'/'+$d,'') $jDate=Iif($y=1899 & $m=12 & $d=30,'',$jDate) $jTime=Iif($jTime,Right("0"+$hh,2)+':'+Right("0"+$mm,2)+':'+Right("0"+$ss,2),'') $fnDateDiff=Iif($jDate & $jTime,$jDate+" "+$jTime,$jDate+$jTime) EndIf Else $fnDateDiff=$Date1 EndIf EndFunction |
|
Top
|
|
|
|
#157552 - 2006-02-21 07:36 PM
Re: Display date last week
|
Chris S.
MM club member
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
In particular...
Code:
fnDateDiff(@DATE,-1,"w",1) ?
|
Top
|
|
|
|
#157555 - 2006-02-23 10:45 PM
Re: Display date last week
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
I turn 4.0 tomorrow, if i forget who i am will someone help me get home?
|
Top
|
|
|
|
#157556 - 2006-02-23 11:22 PM
Re: Display date last week
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
Les asked if you dang kids could quit spouting off how young you are. It's getting harder to remember back that far.
|
Top
|
|
|
|
#157557 - 2006-02-23 11:29 PM
Re: Display date last week
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
roflmao! doc i think the reason you hang out here is so that you can brag that you have forgoten more than most of us babes have learned.
|
Top
|
|
|
|
#157560 - 2006-02-24 06:03 PM
Re: Display date last week
|
ledzepe
Fresh Scripter
Registered: 2005-12-06
Posts: 26
|
Hi everyone,
Nothing fancy here, I just wanna output the date last week (or 7 days ago) to a text file. Anyone think of any simple solution because the best that I can come up is a matrix for January, February, March, 30days and 31 days months. The script is actually big, approx. 15Kb, and it's not flexible because we may change the date to 5 days ago.
|
Top
|
|
|
|
#157564 - 2006-02-24 08:23 PM
Re: Display date last week
|
Jochen
KiX Supporter
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
Not as flexible as Chris very complete solution but as accurate as it can be if the task is only to calculate with days :
DateCalc
sample use:
Code:
break on
"Date 7 Days before today: " + DateCalc(@date,-7)
get $
exit 0
;---- No changes beyond here ----
function DateCalc($date1, $DateOrMod, optional $SingleDigit)
dim $_intDate1, $_intYear1, $_intMonth1, $_intDay1 dim $_intDate2, $_intYear2, $_intMonth2, $_intDay2
$date1 = split($date1,'/') if ubound($date1) <> 2 exit 1 endif
$_intYear1 = val($date1[0]) $_intMonth1 = val($date1[1]) $_intDay1 = val($date1[2])
if $_intMonth1 < 3 $_intMonth1 = $_intMonth1 + 12 $_intYear1 = $_intYear1 - 1 endif
$_intDate1 = $_intDay1 + ( 153 * $_intMonth1 - 457 ) / 5 + 365 * $_intYear1 + $_intYear1 / 4 - $_intYear1 / 100 + $_intYear1 / 400 - 306
select
case vartype($DateOrMod) = 3
$_intDate2 = $_intDate1 + $DateOrMod if instr($_intDate2,'-') $_intDate2 = val(substr($_intDate2,2,len($_intDate2)-1)) endif
$_intYear2 = ( 100 * ( ( ( 100*($_intDate2+306)-25)/3652425) - ( ((100*($_intDate2+306)-25)/3652425)/4) ) + (100*($_intDate2+306)-25) ) / 36525
$_intMonth2 = ( 5 * ( ( ( 100*($_intDate2+306)-25)/3652425) - ( ((100*($_intDate2+306)-25)/3652425)/4) + ($_intDate2+306) - 365 * $_intYear2 - $_intYear2 / 4 ) + 456 ) / 153
$_intDay2 = ( ( ( 100*($_intDate2+306)-25)/3652425) - ( ((100*($_intDate2+306)-25)/3652425)/4) + ($_intDate2+306) - 365 * $_intYear2 - $_intYear2 / 4 ) - ( 153 * $_intMonth2 - 457 ) / 5
if $_intMonth2 > 12 $_intYear2 = $_intYear2 + 1 $_intMonth2 = $_intMonth2 - 12 endif
if not $SingleDigit if len($_intYear2 ) < 4 $_ = execute("for $i=1 to 4-len($$_intYear2) $$_intYear2 = '0' + $$_intYear2 next") endif $_intMonth2 = right("0" + $_intMonth2,2) $_intDay2 = right("0" + $_intDay2,2) endif
$DateCalc = '' + $_intYear2 + '/' + $_intMonth2 + '/' + $_intDay2
case vartype($DateOrMod) = 8
$DateOrMod = split($DateOrMod,'/')
if ubound($DateOrMod) <> 2 exit 1 endif
$_intYear2 = val($DateOrMod[0]) $_intMonth2 = val($DateOrMod[1]) $_intDay2 = val($DateOrMod[2])
if $_intMonth2 < 3 $_intMonth2 = $_intMonth2 + 12 $_intYear2 = $_intYear2 - 1 endif
$_intDate2 = $_intDay2 + ( 153 * $_intMonth2 - 457 ) / 5 + 365 * $_intYear2 + $_intYear2 / 4 - $_intYear2 / 100 + $_intYear2 / 400 - 306
$DateCalc = $_intDate1 - $_intDate2
;comment the next line if you wish to return negative results also !!! if instr($DateCalc,'-') $DateCalc = val(substr($DateCalc,2,len($DateCalc)-1)) endif
case 1
exit 1
endselect
endfunction
I am 36
_________________________
|
Top
|
|
|
|
#157565 - 2006-02-24 10:16 PM
Re: Display date last week
|
ledzepe
Fresh Scripter
Registered: 2005-12-06
Posts: 26
|
Thank you all. I could use Jochen's with some minor modification.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 248 anonymous users online.
|
|
|