DATE() Function - Convert Julian to Calendar Date - BBj

For this topic's original documentation, see the DATE() Function - Convert Julian to Calendar Date.

BBj-Specific Information

Syntax

DATE(num1{,num2}{:str}{,MODE=mode}{,ERR=lineref})
DATE(num1{,num2}{,str}{,MODE=mode}{,ERR=lineref})

Description

The DATE() function takes a Julian date and the optional time-of-day and formats it into a more familiar calendar date and time string.

Parameter

Description

num1

Julian date (0 for the current date). By default, 0 indicates the current date from the server.

In BBj 12.00 and higher, this can be changed to use the date from the client by setting SETOPTS byte 8, bit $08$.

num2

Time of day in SETTIME format (hours and fractional hours). If this parameter is not included, the current time is used. By default, the current time is based on the server.

In BBj 12.00 and higher, this can be changed to use the time from the client by setting SETOPTS byte 8, bit $08$.

str

Output format of the result. If this parameter is not included, the default mask from the first part of STBL("!DATE") is used. The default value of this mask is usually "%Mz/%Dz/%Yz". If STBL("!LOCALE") is modified, the default mask is updated for the new locale. See STBL("!LOCALES") for a line-feed-delimited list of available locales.

MODE=mode

In BBj 12.00 and higher, specify MODE="SERVER" or MODE="CLIENT" to explicitly specify either server or client date and time, independent of  SETOPTS byte 8, bit $08$.

ERR=lineref

Branch to be taken if an error occurs during execution.

The following recognized format indicators all begin with a "%" followed by a letter indicating which component of the date/time to insert:

Format

Description

%Y

Year

%M

Month

%D

Day

%H

Hour (24-hour clock)

%h

Hour (12-hour clock)

%m

Minute

%s

Second

%t

Millisecond (thousandths of a second). Available in BBj 18.0 and higher.

%P

AM/PM (This format is unique to BBj.)

%p

am/pm

%a Localized am/pm string. Available in BBj 24.00 and higher.

%J

Day number within the year (1-366). (This format is unique to BBj.)

%W

Day number within the week (1-7, Sunday=1). This format is unique to BBj.

%w

Week number within the year (1-53, differs by locale).

%d

Day number within the week (1-7, differs by locale). Available in BBj 16.00 and higher

%y

Base year of the current week, available in BBj 16.00 and higher. The first few days of January may fall into the last week of the previous year. The last few days of December may fall into the first week of the following year.

These format indicators can be followed with an optional modifier to describe more specific information:

Modifier

Description

z

Zero-fill

s

Short text

l

Long text

p

Packed number (in CHR() form)

d

Decimal (default format)

The following table provides examples of possible date combinations. Assume the date to be Friday July 11, 2003, the time to be 6:30 PM, and !LOCALE to be en_US (the %y, %w, and %d values are locale-sensitive).

Format

Default

Packed (p)

Decimal (d)

Zero-fill (z)

Short Text (s)

Long Text (l)

%Y

2003

CHR(103)

2003

03

2003

2003

%M

7

CHR(7)

7

07

Jul

July

%D

11

CHR(11)

11

11

Fri

Friday

%H

18

CHR(18)

18

18

18

18

%h

6

CHR(6)

6

06

6

6

%m

30

CHR(30)

30

30

30

30

%s

0

CHR(0)

0

00

0

0

%t

0

(N/A)

0

000

0

0

%P

PM

PM

(N/A)

(N/A)

(N/A)

(N/A)

%p

pm

pm

(N/A)

(N/A)

(N/A)

(N/A)

%a

PM

PM

(N/A)

(N/A)

(N/A)

(N/A)

%J

192

(N/A)

192

192

192

192

%W

6

CHR(6)

6

06

Fri

Friday

%w

28

CHR(28)

28

28

28

28

%d

6

CHR(6)

6

6

Fri

Friday

%y

2003

CHR(103)

2--3

03

2003

2003

The "s" and "l" formats of the day formats (%D, %d, %W) give the text day of the week

The default format may be set by the developer using STBL("!DATE"). The text used for the month and day names is determined based on STBL("!LOCALE"). For example, the following will reset STBL("!DATE") to German month and day names and a date mask of "%Dz.%Mz.%Yz":

X$ = STBL("!LOCALE","de")

Unless you explicitly reset STBL("!LOCALE"), the date mask will default to "%Mz/%Dz/%Yz".

Dates prior to the adoption of the Gregorian calendar are not historically meaningful. Countries adopted the Gregorian calendar at various times starting as early as October 15, 1582 (October 5 on the Julian calendar). Great Britain and its colonies, including the territory that was to become the USA, converted to the Gregorian calendar on September 14th, 1752 (September 3 on the Julian calendar). Some countries did not adopt the Gregorian calendar until well into the 20th century.

DATE(-1) returns "".

Examples

The following is the most simple form and prints the current date:

1000 PRINT DATE(0)

The following outputs the current year.

1000 PRINT DATE(0:"The current year is %Y")

The following example prints a date in "MM/DD/YY" format (requiring the zero-fill operation):

PRINT DATE(0:"%Mz/%Dz/%Yz")

See Also

Date Input - BBj

JUL() - Get Julian Date - BBj

Functions - Alphabetical Listing