Back

Topic

[KB139]Date and time formats from SCADA Basic and VBA

Tags: Scada Basic, Scripting, VBA

14 years ago
By RM
Options
Print
Applies to:

PcVue all versions.


Summary:

This article discusses discrepancies in the ways date-time formatting works in PcVue, SCADA Basic, VBA and animations.


Details:

Calculations of date and time do not always take into account time zone bias and summer/winter bias,  depending on the way you retrieve those values:

  • Using the SCADA Basic instructions DATETIMEVALUE and DATETIMESTRING.
  • Using VBA instructions such as datetime.now.
  • Using the animation Display Register with a Date and Time formatted representation.

Scada Basic

When you use SCADA Basic date-time management functions, the reference day for all of them is the 1st of January 1970. However most of those functions (not only in PcVue) can be used only for date-times after the 1st of January 1980.

For that reason,

DATETIMEVALUE(“01/01/1970″,”00:00:00”)

returns 0 and

DATETIMESTRING(DATETIMEVALUE(“01/01/1970″,”00:00:00”))

is unable to return an useful string.

These differ as follows

Date_and_time1

This explains why you get differences of one or more hours when using date-times from PcVue and/or the from DATETIMESTRING function, from those obtained with the DATETIMEVALUE function. The discrepancy depends on the local time zone and whether the operating system has switched to or from seasonal time.

Note

Local time is UMT time adjusted by local time bias (i.e. time zone bias + summer/winter bias.)

Note

In summary: when using SCADA Basic, do not use the DATETIMEVALUE or DATETIMESTRING instructions for dates prior to 1980, or for local time bias.

VBA

Many functions are available in VBA to retrieve date and time (date, datevalue, datetime module).

For instance:

Date_and_time2

Animations

Suppose your PC is set to GMT+1 (i.e. with summer time adjustment). A shift when you display in DATETIMESTRING format the content of a register variable @NOW coming from the VBA Datetime.Now function.

The animation format Date and Time always displays a UTC Time.

Solution

In SCADA Basic:

  • Do not use the instructions DATETIMEVALUE or DATETIMESTRING for dates prior to 1980.
  • Do not use the DATETIMEVALUE if the local time bias matters in the application.

Example

Suppose that your PC is set to UTC+1 (for the summer time adjustment), and the register variable @NOW is configured as follows:

KB_Custom_Display_Format_dialog_dates

In VBA you could update @NOW as follows:

Private Sub Text1_Click()

[@NOW] = DateTime.Time & ” ” & DateTime.Date

End Sub

In SCADA Basic you could update it as follows:

Sub Main()

@NOW = Datetimestring( Datetimevalue() , “#h:#m:#s #D/#M/###Y”);

End Sub

Note

In PcVue, a register variable has the numerical capacity for such dates, but you will have to increase the variable’s default Maximum of 64K to a large number.

This mimic shows the results from PcVue, VBA and SCADA Basic, within a few seconds of clicking the buttons to run each script:

KB_SB_and_VBA_dates_mimic

The times given by PcVue, SCADA Basic and the VBA script reflect the time zone bias (UMT+0) and British Summer Time (i.e. +1 hour), but the value displayed with date and time format does not.

Further information

The date and time handling functions are described and illustrated in the Help for PcVue:

Date_and_time5


Created on: 05 Nov 2010 Last update: 13 May 2024