Programming Guide


Gets the formatted system date and time

char *sm_sdtime(char *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.



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-19 Date/time format options

Unit Description Token


4 digit (e.g., 1990)


2 digit (e.g., 90)



1 or 2 digit (1 - 12)


2 digit (01 - 12)


full name (e.g., January)


3 character name (e.g., Jan)



1 or 2 digit (1 - 31)


2 digit (01 - 31)


day of the week

full name (e.g., Sunday)


3 character name (e.g., Sun)


numeric day of the week (1-7)


day of the year

digit (1 - 366)



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


2 digit (01 -12 or 00 -23)



1 or 2 digit (0 - 59)


2 digit (00 - 59)



1 or 2 digit (0 - 59)


2 digit (00 - 59)


AM or PM

for use with a 12-hour clock


literal percent

use % as a literal character


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



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.


#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