Programming Guide



sm_sdtime

Gets the formatted system date and time

char *sm_sdtime(char *format);

format
Specifies the format to use with an expression that starts with y or n, followed by any combination of date/time tokens and literal text. y indicates a 12-hour clock; n or any other character indicates a 24-hour clock. This character is required even if the format does not include time tokens. The table in Description shows the date/time tokens that you use to build a format expression.

Returns

Description

sm_sdtime gets the current date and/or time from the operating system and returns it in the format-specified format.

The following table lists the tokens you use to build a format expression. All tokens are prefixed by the percent sign (%) and are case-sensitive.

Table 5-17 Date/time format options

Unit Description Token

year

4 digit (e.g., 1990)

%4y

2 digit (e.g., 90)

%2y

month

1 or 2 digit (1 - 12)

%m

2 digit (01 - 12)

%0m

full name (e.g., January)

%*m

3 character name (e.g., Jan)

%3m

day

1 or 2 digit (1 - 31)

%d

2 digit (01 - 31)

%0d

day of the week

full name (e.g., Sunday)

%*d

3 character name (e.g., Sun)

%3d

numeric day of the week (1-7)

%.d

day of the year

digit (1 - 366)

%+d

hour

1 or 2 digit (1 - 12 or 0 - 23)

%h

2 digit (01 -12 or 00 -23)

%0h

minute

1 or 2 digit (0 - 59)

%M

2 digit (00 - 59)

%0M

second

1 or 2 digit (0 - 59)

%s

2 digit (00 - 59)

%0s

AM or PM

for use with a 12-hour clock

%p

literal percent

use % as a literal character

%%

default formats from the message file (refer to "Date/Time Defaults" in Application Development Guide)

SM_0DEF_DTIME
SM_1DEF_DTIME
...
SM_9DEF_DTIME

%0f
%1f
...
%09f

At runtime, Panther strips off the first character of format. If the character is y, it uses a 12-hour clock; otherwise, it uses the 24-hour clock. Next, it examines the rest of format, replacing any tokens with the appropriate values. All non-token characters are treated as literal values.

The message file contains the text for day and month names, AM and PM, and the tokens for the default formats. You can modify these. Refer to "Date/Time Defaults" in Application Development Guide for details.

sm_sdtime uses a 256-byte static buffer that it shares with other date and time formatting functions. Because Panther does not check for overflow, process the returned string or copy it to a local variable immediately.

Example

#include <smdefs.h>
/* Put current date MONTH-DAY-YEAR in the field "time". */
char *format;
format = "n%m-%0d-%2y";
sm_n_putfield("time", sm_sdtime(format));

See Also

sm_udtime