[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: Count calendar days



PureBytes Links

Trading Reference Links

That is because StrToDateTime( Datestr ) with date-only string as input,
will give you "END OF DAY" date which is 23:59:59.9999999
and that is this one day more.

JScript version will give you "midnight" 0:00:00 AM beginning of the day.

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message ----- 
From: "ricko8294_98" <ricko@xxxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Thursday, October 22, 2009 2:31 AM
Subject: [amibroker] Re: Count calendar days


> Interestingly, converting the 5.27 or higher version to a function,
>
> function getdaystill( y, m, d )
> {
>    SecInDay = 60 * 60 * 24;
>    Datestr = NumToStr( y, 1.0, False )  + "-" + NumToStr( m, 2.0 ) + "-" + NumToStr( d, 1.0 );
>    return floor( DateTimeDiff( Now( 5 ) ) / SecInDay ) ;
> }
> and calling it like
>
> Days = getdaystill(2010,1,1);
>
> it returns 72 (today is Oct 21)
>
> while the other version (at the bottom) returns 71.
>
> I guess 72 includes either today or the target date.
>
> Rick
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@xxx> wrote:
>>
>> Hello,
>>
>> Alternativelly if you are using 5.27 or higher you can use AFL-only solution
>>
>> SecInDay = 60 * 60 * 24;
>> "Calendar days from today till January 1st, 2010 = " + floor( DateTimeDiff( StrToDateTime("2010-01-01"), Now( 5 ) )/SecInDay ) ;
>>
>>
>>
>> Also the old code needs amendment because JScript Date() gets month as 0..11 (instead of 1..12)
>>
>>
>>
>> EnableScript("JScript");
>> <%
>> function GetDaysTill( y, m, d )
>> {
>>   msecPerDay = 1000 * 60 * 60 * 24;
>>
>>   dt = new Date( y, m-1, d, 23, 59, 59 );
>>   today = new Date();
>>
>>   distance = dt.getTime() - today.getTime();
>>
>>   return Math.floor( distance/msecPerDay  );
>> }
>> %>
>>
>> sc = GetScriptObject();
>>
>> "Calendar days from today till January 1st, 2010 = " + sc.GetDaysTill( 2010, 1, 1 );
>>
>>
>> Best regards,
>> Tomasz Janeczko
>> amibroker.com
>> ----- Original Message ----- 
>> From: "Tomasz Janeczko" <groups@xxx>
>> To: <amibroker@xxxxxxxxxxxxxxx>
>> Sent: Wednesday, October 21, 2009 5:50 PM
>> Subject: Re: [amibroker] re: Count calendar days
>>
>>
>> > Hello,
>> >
>> > Sorry, I was writing from memory and forgot that DaysSince1900 does not take arguments therefore can not be used for that 
>> > purpose.
>> >
>> > Instead use this:
>> >
>> > EnableScript("JScript");
>> > <%
>> > function GetDaysTill( y, m, d )
>> > {
>> >  msecPerDay = 1000 * 60 * 60 * 24;
>> >
>> >  dt = new Date( y, m, d, 0, 0, 0 );
>> >  today = new Date();
>> >
>> >  distance = dt.getTime() - today.getTime();
>> >
>> >  return Math.floor( distance / msecPerDay );
>> > }
>> > %>
>> >
>> > sc = GetScriptObject();
>> >
>> > "Calendar days from today till January 1st, 2010 = " + sc.GetDaysTill( 2010, 1, 1 );
>> >
>> > Best regards,
>> > Tomasz Janeczko
>> > amibroker.com
>> > ----- Original Message ----- 
>> > From: "sebastiandanconia" <sebastiandanconia@xxx>
>> > To: <amibroker@xxxxxxxxxxxxxxx>
>> > Sent: Wednesday, October 21, 2009 5:21 PM
>> > Subject: [amibroker] re: Count calendar days
>> >
>> >
>> >> (response got mixed up with different poster)
>> >>
>> >> Tomasz said:  "You can use DateTimeConvert in conjunction with DaysSince1900.  First one will convert from string representing
>> >> date to datetime format and second one will report number of days. By subtracting this and DaysSince1900 of today you will get
>> >> number of calendar days till future date."
>> >>
>> >> Tomasz, you've never yet let me down.:)  I'll give that a whirl and post the code when I get it puzzled out.
>> >>
>> >>
>> >> Sebastian
>> >>
>> >>
>> >>
>> >> ------------------------------------
>> >>
>> >> **** IMPORTANT PLEASE READ ****
>> >> This group is for the discussion between users only.
>> >> This is *NOT* technical support channel.
>> >>
>> >> TO GET TECHNICAL SUPPORT send an e-mail directly to
>> >> SUPPORT {at} amibroker.com
>> >>
>> >> TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
>> >> http://www.amibroker.com/feedback/
>> >> (submissions sent via other channels won't be considered)
>> >>
>> >> For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
>> >> http://www.amibroker.com/devlog/
>> >>
>> >> Yahoo! Groups Links
>> >>
>> >>
>> >>
>> >
>> >
>> >
>> > ------------------------------------
>> >
>> > **** IMPORTANT PLEASE READ ****
>> > This group is for the discussion between users only.
>> > This is *NOT* technical support channel.
>> >
>> > TO GET TECHNICAL SUPPORT send an e-mail directly to
>> > SUPPORT {at} amibroker.com
>> >
>> > TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
>> > http://www.amibroker.com/feedback/
>> > (submissions sent via other channels won't be considered)
>> >
>> > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
>> > http://www.amibroker.com/devlog/
>> >
>> > Yahoo! Groups Links
>> >
>> >
>> >
>>
>
>
>
>
> ------------------------------------
>
> **** IMPORTANT PLEASE READ ****
> This group is for the discussion between users only.
> This is *NOT* technical support channel.
>
> TO GET TECHNICAL SUPPORT send an e-mail directly to
> SUPPORT {at} amibroker.com
>
> TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
> http://www.amibroker.com/feedback/
> (submissions sent via other channels won't be considered)
>
> For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> http://www.amibroker.com/devlog/
>
> Yahoo! Groups Links
>
>
>



------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/