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
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.
Computing a difference between two dates or times is quite complicated and would require several tens of lines.
To truncate a division, use FLOOR(dividend/divisor,0).
Thanks Roberto,
to convert a Date into Year, Month, & Day from what you stating this works
TheDate = 20240213
TheYear = Floor(TheDate / 10000, 0)
TempDay = Floor(TheDate / 100, 0)
TheDay = ((TheDate / 100) - TempDay) * 100
TempMonth = Floor(TheDate / 100, 0) * 100
TempMonth2 = TempMonth / 10000
TheMonth = (TempMonth2 - Floor(TempMonth / 10000, 0)) * 100
PRINT(TheYear)
PRINT(TheMonth)
PRINT(TheDay)
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
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!
You can do some math with seconds between two dates using the timestamp system constant https://www.prorealcode.com/documentation/timestamp/.
Hello Roberto,
Thats exactly what I ended up doing. 🙂
// I pass into the indicator a serial number of the date I am interested in
// this Offset is positive if the date in question is after Jan 1st, 1970
// and negative if the date is before Jan 1st, 1970
Count = Floor(OpenTimestamp/86400,0) - Offset
This has exactly what I need
Again thanks for the help and guidance
Scott