Extracting Day and Month from a Date in ProBuilder

10 Jul 2020
0 comment
0 attachment

This code snippet demonstrates how to extract the day and month from a numerical date format (YYYYMMDD) using basic arithmetic operations in ProBuilder language.


// Extract Day
x = date // x = 20190326
y = round((x / 100) - 0.5) // y = 201903.00
z = y * 100 // z = 20190300
d = x - z // d = 26

// Extract Month
x = date // x = 20190326
y = round((x / 100) - 0.5) // y = 201903.00
z = round((y / 100) - 0.5) // z = 2019.0000
m = y - z // m = 3

The code provided uses a combination of division, multiplication, and subtraction to isolate the day and month components from a date given in the format YYYYMMDD.

  • Extracting the Day:
    • The variable x is assigned the full date.
    • y is calculated by dividing x by 100 and rounding the result to remove the last two digits (day part).
    • z is then calculated by multiplying y back by 100, effectively giving us the year and month in YYYYMM00 format.
    • Finally, d (day) is obtained by subtracting z from x, which leaves us with the last two digits representing the day.
  • Extracting the Month:
    • Using the same initial steps, x and y are calculated as before.
    • z is recalculated by dividing y by 100 and rounding, which isolates the year (YYYY).
    • The month m is then extracted by subtracting z from y, leaving the middle two digits which represent the month.

This method is straightforward and utilizes basic arithmetic to manipulate the date format, making it a useful technique for date handling in ProBuilder scripts.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/tomorrows-date/#post-94733

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
robertogozzi Master
Roberto https://www.ots-onlinetradingsoftware.com
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
134
strategy
171

Recent Snippets

How to Track Up/Down Cumulative Volume Inside Each Candle (Tick Volume Delta)
indicator
This snippet separates the real-time, intra-candle volume into up-volume and down-volume based on whether the last [...]
How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Logo Logo
Loading...