Overbasic – Date/Time functions

My.DateTime category contains all built-in functions available in Overbasic for accessing dates.

DateAdd #

Adds a time interval (expressed in Milliseconds, Seconds, Minutes, Hours, Days, Months, Years), to a date/time.

Result type: an integer representing a date or time

Arguments:

  • DATE: an integer representing a date in YYYYMMDD format (where YYYY = year; MM = month; DD = day)
  • TIME: an integer representing a time in HHMMSSFFFCCCN format (where HH = hours; MM = minutes; SS = seconds; FFF = milliseconds; CCC = microseconds; N = nanoseconds (hundreds)
  • INTERVAL: time interval to add:
    • F: millisecond
    • S: second
    • MIN: minute
    • H: hour
    • D: day
    • M: month
    • Y: year
  • NUMBER OF INTERVALS: number of time intervals to add/subtract to DATE/TIME. If greater than zero, the intervals will be added to DATE/TIME, if less than zero they will be subtracted.
  • VALUE TO RETURN:
    • D: function returns a date in YYYYMMDD format
    • T: function returns a time in HHMMSSFFFCCCN format

Examples:

Dim t As Numeric = My.DateTime.DateAdd(20220101, 1200000000000, "MIN", 5, "T")
'Result: 1205000000000

Dim t As Numeric = My.DateTime.DateAdd(20220101, 1200000000000, "MIN", -5, "T")
'Result: 1155000000000

Day #

Returns the Day of current bar or of the bar obtained by adding the OFFSET argument to current bar.

Result type: an integer representing the day in DD format

Arguments:

  • OFFSET: (optional) difference (in bars) between current bar and the bar containing the data to get. Eg. To get data of 2 bars back the current bar, set OFFSET equal to -2.

Examples:

'The following line of code returns the day of current bar:
Dim d As Numeric = My.DateTime.Day
'Result: if the date of current bar is 20230315, the result will be 15

'The following line of code returns the day of 2 bars back the current bar:
Dim d As Numeric = My.DateTime.Day(-2)

DayOfWeek #

Returns the Day of Week of current bar or of the bar obtained by adding the OFFSET argument to current bar.

Result type: an integer (from 1 to 7) representing the day of week:

  • 1 = Sunday
  • 2 = Monday
  • 3 = Tuesday
  • 4 = Wednesday
  • 5 = Thursday
  • 6 = Friday
  • 7 = Saturday

Arguments:

  • OFFSET: (optional) difference (in bars) between current bar and the bar containing the data to get. Eg. To get data of 2 bars back the current bar, set OFFSET equal to -2.

Examples:

'The following line of code returns the day of week of current bar:
Dim dw As Numeric = My.DateTime.DayOfWeek

'The following line of code returns the day of week of 2 bars back the current bar:
Dim dw As Numeric = My.DateTime.DayOfWeek(-2)

Hour #

Returns the Hour of current bar or of the bar obtained by adding the OFFSET argument to current bar.

Result type: an integer representing the hour in HH format

Arguments:

  • OFFSET: (optional) difference (in bars) between current bar and the bar containing the data to get. Eg. To get data of 2 bars back the current bar, set OFFSET equal to -2.

Examples:

'The following line of code returns the hour of current bar:
Dim h As Numeric = My.DateTime.Hour
'Result: if the time of current bar is 1215345002679, the result will be 12

'The following line of code returns the hour of 2 bars back the current bar:
Dim h As Numeric = My.DateTime.Hour(-2)

MicroSecond #

Returns the MicroSeconds of current bar or of the bar obtained by adding the OFFSET argument to current bar.

Result type: an integer representing the microseconds in CCC format

Arguments:

  • OFFSET: (optional) difference (in bars) between current bar and the bar containing the data to get. Eg. To get data of 2 bars back the current bar, set OFFSET equal to -2.

Examples:

'The following line of code returns the microseconds of current bar:
Dim c As Numeric = My.DateTime.MicroSecond
'Result: if the time of current bar is 1215345002679, the result will be 267

'The following line of code returns the microseconds of 2 bars back the current bar:
Dim c As Numeric = My.DateTime.MicroSecond(-2)

MilliSecond #

Returns the MilliSeconds of current bar or of the bar obtained by adding the OFFSET argument to current bar.

Result type: an integer representing the miilliseconds in FFF format

Arguments:

  • OFFSET: (optional) difference (in bars) between current bar and the bar containing the data to get. Eg. To get data of 2 bars back the current bar, set OFFSET equal to -2.

Examples:

'The following line of code returns the milliseconds of current bar:
Dim c As Numeric = My.DateTime.MilliSecond
'Result: if the time of current bar is 1215345002679, the result will be 500

'The following line of code returns the milliseconds of 2 bars back the current bar:
Dim c As Numeric = My.DateTime.MilliSecond(-2)

Minute #

Returns the Minutes of current bar or of the bar obtained by adding the OFFSET argument to current bar.

Result type: an integer representing the minutes in MM format

Arguments:

  • OFFSET: (optional) difference (in bars) between current bar and the bar containing the data to get. Eg. To get data of 2 bars back the current bar, set OFFSET equal to -2.

Examples:

'The following line of code returns the minutes of current bar:
Dim m As Numeric = My.DateTime.Minute
'Result: if the time of current bar is 1215345002679, the result will be 15

'The following line of code returns the minutes of 2 bars back the current bar:
Dim m As Numeric = My.DateTime.Minute(-2)

Month #

Returns the Month of current bar or of the bar obtained by adding the OFFSET argument to current bar.

Result type: an integer representing the month in MM format

Arguments:

  • OFFSET: (optional) difference (in bars) between current bar and the bar containing the data to get. Eg. To get data of 2 bars back the current bar, set OFFSET equal to -2.

Examples:

'The following line of code returns the month of current bar:
Dim m As Numeric = My.DateTime.Month
'Result: if the date of current bar is 20230315, the result will be 3

'The following line of code returns the month of 2 bars back the current bar:
Dim m As Numeric = My.DateTime.Month(-2)

NanoSecond #

Returns the NanoSeconds of current bar or of the bar obtained by adding the OFFSET argument to current bar.

Result type: an integer representing the nanoseconds in N format

Arguments:

  • OFFSET: (optional) difference (in bars) between current bar and the bar containing the data to get. Eg. To get data of 2 bars back the current bar, set OFFSET equal to -2.

Examples:

'The following line of code returns the nanoseconds of current bar:
Dim n As Numeric = My.DateTime.NanoSecond
'Result: if the time of current bar is 1215345002679, the result will be 9

'The following line of code returns the nanoseconds of 2 bars back the current bar:
Dim n As Numeric = My.DateTime.NanoSecond(-2)

Second #

Returns the Seconds of current bar or of the bar obtained by adding the OFFSET argument to current bar.

Result type: an integer representing the seconds in SS format

Arguments:

  • OFFSET: (optional) difference (in bars) between current bar and the bar containing the data to get. Eg. To get data of 2 bars back the current bar, set OFFSET equal to -2.

Examples:

'The following line of code returns the seconds of current bar:
Dim s As Numeric = My.DateTime.Second
'Result: if the time of current bar is 1215345002679, the result will be 34

'The following line of code returns the seconds of 2 bars back the current bar:
Dim s As Numeric = My.DateTime.Second(-2)

Week #

Returns the week number of current bar or of the bar obtained by adding the OFFSET argument to current bar.

Result type: an integer (from 1 to 53) representing the week number

Arguments:

  • OFFSET: (optional) difference (in bars) between current bar and the bar containing the data to get. Eg. To get data of 2 bars back the current bar, set OFFSET equal to -2.

Examples:

'The following line of code returns the week number of current bar:
Dim w As Numeric = My.DateTime.Week

'The following line of code returns the week number of 2 bars back the current bar:
Dim w As Numeric = My.DateTime.Week(-2)

Year #

Returns the Year of current bar or of the bar obtained by adding the OFFSET argument to current bar.

Result type: an integer representing the year in YYYY format

Arguments:

  • OFFSET: (optional) difference (in bars) between current bar and the bar containing the data to get. Eg. To get data of 2 bars back the current bar, set OFFSET equal to -2.

Examples:

'The following line of code returns the year of current bar:
Dim y As Numeric = My.DateTime.Year
'Result: if the date of current bar is 20230315, the result will be 2023

'The following line of code returns the year of 2 bars back the current bar:
Dim y As Numeric = My.DateTime.Year(-2)