SheerPower® 4GL
A Guide to the SheerPower Language


Previous Contents Index

6.3.3 DAYS(str_expr [, int_num])

Given a date in CCYYMMDD or YYMMDD format, the DAYS function returns the number of days since January 1, 1600 (this date is day 1). This number is called the Julian day.

Example 6-40 DAYS function

  print days('20000122') 
  print days('990122') 
  end
 
 
146119 
145754 

int_num indicates the desired input format for the date. The default input format is zero. If the century is not included, it assumes 1900 as the century.

Table 6-2 DAYS function - integer values
Value (int_num) Input Date Format
0 CCYYMMDD or YYMMDD
1 MMDDCCYY or MMDDYY
2 DDMMCCYY or DDMMYY
3 DD-Mon-CCYY or DD-Mon-YY
4 Month DD, CCYY

Example 6-41 DAYS function - integer values

  print days('20000103',0) 
  print days('01032000',1) 
  print days('03012000',2) 
  print days('03-Jan-2000',3) 
  print days('January 3, 2000',4) 
  end
 
 
146100 
146100 
146100 
146100 
146100 

6.3.4 DAY$[(int_expr)]

Given an integer expression specifying the number of days since January 1, 1600, DAY$ returns the day of the week. If no integer expression is given, DAY$ returns the day of the week for today's date. The day is returned as a string expression (Friday, Saturday, etc.).

Example 6-42 DAY$ function

  print day$
 
 
Saturday 

6.3.5 FULLTIME$[(float_expr, [int_var])]

Given the number of seconds since the SheerPower base date, the FULLTIME$ function returns the date and time in one of the formats given below.

float_expr is the number of seconds since the SheerPower base date. The default is the current date and time. January 1, 1600 00:00:00 is considered the second 0.

Table 6-3 FULLTIME$ function - integer values
Value (int_var) Output Data Format
0 CCYYMDD HHMMSS
1 MMDDCCYY HHMMSS
2 DDMMCCYY HHMMSS
3 DD-Mon-CCYY HH:MM:SS
4 Month DD, CCYY HH:MM:SS

Example 6-43 FULLTIME$ function

  print fulltime$
  sec = seconds('20000121 115042') 
  print fulltime$(sec, 0) 
  print fulltime$(sec, 1) 
  print fulltime$(sec, 2) 
  print fulltime$(sec, 3) 
  print fulltime$(sec, 4) 
  end
 
 
20000208 232653 
20000121 115042 
01212000 115042 
21012000 115042 
21-Jan-2000 11:50:42 
January 21, 2000 11:50:42 

6.3.6 SECONDS(str_expr)

Given a full-time string in CCYYMMDD HHMMSS, YYMMDD HHMMSS, HHMMSS or HHMM format, the SECONDS function returns the number of seconds since the SheerPower base date (January 1, 1600 00:00:00).

The number of seconds is returned as a floating point number.

Example 6-44 SECONDS function

  z  = seconds('20000122 103050') 
  z1 = seconds('990122 103050') 
  z2 = seconds('103050') 
  z3 = seconds('1030') 
  print 'Seconds cymdhms ='; z 
  print 'Seconds  ymdhms ='; z1 
  print 'Seconds     hms ='; z2 
  print 'Seconds     hm  ='; z3 
  end
 
 
Seconds cymdhms = 12624633050 
seconds  ymdhms = 12593097050 
seconds     hms = 37850 
seconds     hm  = 37800 

6.3.7 TIME(int_expr)

The value returned by the TIME function depends on the value of int_expr.

If int_expr = 0, TIME returns the number of seconds since midnight.

If int_expr = 1, TIME returns the CPU time of the process in tenths of a second.

If int_expr = 2, TIME returns connect time of the current process in minutes.

Example 6-45 TIME function

  print time(0) 
  print time(1) 
  print time(2) 
  end
 
 
67004 
1 
0 

6.3.8 TIME(5)

TIME(5) returns the number of seconds since SheerPower was invoked. This function can be used to time events to the nearest 100th/sec.

Example 6-46 TIME(5) function

  print time(5)
 
 
 .03 

6.3.9 TIME$

or

TIME$(num_expr)

If num_expr is NOT specified, TIME$ returns the current time of day in HH:MM:SS format.

num_expr is the number of seconds since midnight. The result is returned in HH:MM format.

Example 6-47 TIME$ function

  print time$(1800) 
  print time$(54178) 
  print time$
  end
 
 
00:30 
15:02 
11:33:27 

6.3.10 Pivot Date

Many applications allow the end-user to enter a six-digit date. For a six-digit date, SheerPower 4GL needs to know if the YEAR is in the 19th century or the 20th century. For example:


  161231 

Is this 1916, December 31st or is this 2016, December 31st?

By default, SheerPower assumes that if a six-digit date is given, and the YEAR is less than 20, then this is the 20th century. In the example above,:


  161231 --> December 31, 2016 

The default PIVOT DATE is year 20.

The default pivot date can be changed by creating a logical:


  SheerPower_Y2K_PIVOT 

This can be done with the following small program:

Example 6-48 Pivot Date Logical

  set system, logical 'SheerPower_Y2K_PIVOT': value '17' 

You can add the following to the c:\sheerpower\sp4gl_YOURNAME.ini file:


[logicals] 
SheerPower_Y2K_PIVOT=17 

Then the value will automatically be setup for all SheerPower applications. The logical is checked for only ONCE at sp4gl.exe STARTUP time.

6.4 String Manipulation Functions

The following are string manipulation functions that SheerPower performs:

6.4.1 ASCII(str_expr)

The ASCII function returns the decimal ASCII value of a string's first character. It is returned as an integer. The Section 6.4.4 is the opposite of the ASCII function.

Example 6-49 ASCII function

  print ascii('A') 
 
 
65 

6.4.2 CHANGE$(str_expr1, str_expr2, str_expr3)

CHANGE$ changes specified characters in str_expr1. str_expr1 is the source string. str_expr2 contains the target characters, and str_expr3 specifies the substitution characters. CHANGE$ returns the changed string.

CHANGE$ searches for the target characters within the source string and replaces these characters with the substitution characters. The substitution characters are mapped onto the target characters.

Example 6-50 CHANGE$ function

  let a$ = 'bdbdbdbd' 
  let b$ = 'b' 
  let c$ = 'c' 
  let changed$ = change$(a$, b$, c$) 
  print a$ 
  print changed$ 
  end
 
 
bdbdbdbd 
cdcdcdcd 

6.4.3 CHARSET$[(str_expr)]

CHARSET$ returns the character set specified. The optional string expression can be used to specify the character set to return. The available character sets are:

Table 6-4 Available character sets for CHARSET$
  UCASE all upper-case letters (A-Z)
  LCASE all lower-case letters (a-z)
  CONTROL all control characters (ASCII 0-31)
  ASCII the ASCII character set, in order (0-255)

ASCII is the default character set for CHARSET$.

Example 6-51 CHARSET$ function

  line input 'Enter your text': text$ 
  // change upper-case to lower-case 
  ct$ = change$(text$, & 
       charset$('ucase'), & 
       charset$('lcase')) 
  print 'Lower-case version is:'; ct$ 
  end
  
  
Enter your text? TESTER 
Lower-case version is: tester 


Previous Next Contents Index