Need help with Date
Forums › ProRealTime English forum › ProBuilder support › Need help with Date
- This topic has 7 replies, 2 voices, and was last updated 9 months ago by kingmordecai.
-
-
02/13/2024 at 3:19 PM #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
02/13/2024 at 5:13 PM #228085Here 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.
02/13/2024 at 5:16 PM #228086Computing a difference between two dates or times is quite complicated and would require several tens of lines.
02/13/2024 at 5:19 PM #228087To truncate a division, use FLOOR(dividend/divisor,0).
1 user thanked author for this post.
02/13/2024 at 6:58 PM #228103Thanks Roberto,
to convert a Date into Year, Month, & Day from what you stating this works
123456789101112TheDate = 20240213TheYear = Floor(TheDate / 10000, 0)TempDay = Floor(TheDate / 100, 0)TheDay = ((TheDate / 100) - TempDay) * 100TempMonth = Floor(TheDate / 100, 0) * 100TempMonth2 = TempMonth / 10000TheMonth = (TempMonth2 - Floor(TempMonth / 10000, 0)) * 100PRINT(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
02/13/2024 at 7:07 PM #228104ok 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.
02/14/2024 at 10:41 AM #228150You 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.
02/14/2024 at 12:01 PM #228163Hello Roberto,
Thats exactly what I ended up doing. 🙂
How I am handling this1234// 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, 1970Count = Floor(OpenTimestamp/86400,0) - OffsetThis has exactly what I need
Again thanks for the help and guidance
Scott
-
AuthorPosts
Find exclusive trading pro-tools on