Xbasic

Date and Time Format Elements

Description

A date format is created from the following date format elements.

To include separators in the formatted result, include separators in the format string. For example, "MON, d-yyyy". To use a format code a separator, precede the code with the escape character ("\").

Time formatting defaults to 24 hour time unless otherwise specified in the format.

Element

Description

Example Output

0

Format element (causes a time element h, m, or s, to be returned with a leading 0).

01, 08, 06

s

Second

33,5

1

Display fractional seconds to 1 decimal place.

.5

2

Display fractional seconds to 2 decimal places.

.13

3

Display fractional seconds to 3 decimal places.

.599

m

Minute

59,10,9

h

Hour

12, 1

a

12 hour clock with "a" or "p" suffix.

a, p

am

12 hour clock with "am" or "pm" suffix

am, pm

A

12 hour clock with "A" or "P" suffix

A, P

AM

12 hour clock with "AM" or "PM" suffix

AM, PM

d

day (one digit)

3

dd

day (two digits, 0 pad)

03, 15

x

day with "st", "rd", "th" etc (e.g. 1st, 2nd, 23rd)

1st, 2nd, 23rd

X

day spelled out

First, Second, Twenty Third

W

weekday (three character, upper case)

SUN, MON

w

weekday (three character, lower case)

sun, mon

WEEKDAY

weekday (full name, upper case)

SUNDAY, MONDAY

weekday

weekday (full name, lower case)

sunday, monday

Weekday

weekday (full name, proper case)

Sunday, Monday

M

month (one digit)

1

MM

month (two digits, zero pad)

01, 10

MON

month (three character name, upper case)

JAN, FEB

mon

month (three character name, lower case)

jan, feb

Mon

month (three character name, proper case)

Jan, Feb

MONTH

month (full name, upper case)

JANUARY, FEBRUARY

month

month (full name, lower case)

january, february

Month

month (full name, proper case)

January, February

y

year (two digits)

99, 03

yy

year (two digits)

99, 03

yyyy

year (four digits)

1999, 2003

Format Examples 

curr = now()

? time("0h:0m",curr)
= "19:14"

? time("0h:0m a",curr)
= "07:14 p"

? time("dd-Month-yyyy",curr)
= "21-June-2021"

? time("Weekday, Mon dd, h:m am",curr)
= "Monday, Jun 21, 7:14 pm"

? time("X Weekday of Month",curr)
= "Twenty First Monday of June"

? time("h:m:s.3 a",curr)
= "7:14:59.224 p"

? time("0h:0m:0s.3 a",curr)
= "07:14:59.224 p"

? time("Current \Mont\h: Month",curr)
= "Current Month: June"

See Also