Need help with Date

Forums ProRealTime English forum ProBuilder support Need help with Date

Viewing 8 posts - 1 through 8 (of 8 total)
  • #228059

    Hello to All,

     

    Date is in the format YYYYMMDD

    is there a way to take a date and algorithmically extract the year, month and day

    Or is there a way to get the number of days between two days?

    When I PRINT(19800220 – 19791215) I get the mathematically correct answer of 8886 but not the number of days

    Also is there a way to algorithmically to convert a date to days?

    It seems all of the temporal functions correspond to the bar number but only for the bars in your history, what I am looking for are ways to calculate these things independent of bar history

     

    Thank you for your Time

    Scott

     

    #228085

    Here is s snippet to retrieve tha DAY and MONTH https://www.prorealcode.com/topic/tomorrows-date/#post-94733.

    A Date is just an 8-digit number in the format YYYYMMDD.

    To retrieve the DAY simply divide it by 100 truncating the result. Multiply the result by 100 and The DAY is the difference between the result and the original date.

    Use the latter result in the format YYYYMM00 and divide it by 10000, truncating the result. You’ll get YYYY0000. The difference between the two numbets, divided by 100, is the MONTH.

    You can retrieve the YEAR with yhe result YYYY0000 MOD 10000.

     

     

    #228086

    Computing a difference between two dates or times is quite complicated and would require several tens of lines.

     

    #228087

    To truncate a division, use FLOOR(dividend/divisor,0).

     

    1 user thanked author for this post.
    #228103

    Thanks Roberto,

    to convert a Date into Year, Month, & Day from what you stating this works

    So that is working thank you!

     

    It seems to me that to work with Dates will be very cumbersome in the way that RealTimePro has the Date keyword programmed.

    My main goal is write a function where I pass it two normal dates or Unix Time stamps or excel serial date numbers and it returns the number of days between the two.

    Does anyone have any ideas on how I can go about programming this type of functionality?

    Thank you for your Time

    Scott

    #228104

    ok I think I will just tackle this by using the number days elapsed from Jan 1st 1900 and keep all of my references to dates in the format of days since that date.

     

    Again thanks to Roberto, for helping me visualize how to tackle my problem!

    1 user thanked author for this post.
    #228150

    You can do some math with seconds between two dates using the timestamp system constant https://www.prorealcode.com/documentation/timestamp/.

     

    1 user thanked author for this post.
    #228163

    Hello Roberto,

     

    Thats exactly what I ended up doing. 🙂

    This has exactly what I need

    Again thanks for the help and guidance

    Scott

Viewing 8 posts - 1 through 8 (of 8 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login