image\bbj40.gifDATE() Function - Convert Julian to Calendar Date


Syntax

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

Description

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

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.

num2

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

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.

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

%P

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

%p

am/pm

%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). This format is unique to BBj.

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 and the time to be 6:30 PM.

Format

Default

Packed Number

Decimal

Zero-fill

Short Text

Long Text

%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

%P

PM

PM

(N/A)

(N/A)

(N/A)

(N/A)

%p

pm

pm

(N/A)

(N/A)

(N/A)

(N/A)

%J

192

(N/A)

192

192

192

192

%W

6

CHR(6)

6

06

6

6

%w

29

CHR(29)

29

29

29

29

 

The "s" and "l" formats of the day (%D) give the 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")