rstrdate() 函数将字符串转换为内部的 DATE。
语法
mint rstrdate(inbuf, jdate)
char *inbuf;
int4 *jdate;
inbuf
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 906 -
指向包含要转换的日期的字符串的指针。
jdate
指向接收 inbuf 字符串的内部 DATE 值的 int4 整数的指针。
用法
对于缺省的语言环境 US English, rstrdate() 函数以下列优先顺序来确定如何格式化
该字符串:
DBDATE 环境变量指定的格式(如果设置 DBDATE 的话)。
GL_DATE 环境变量指定的格式(如果设置 GL_DATE 的话)。
缺省的日期形式:mm/dd/yyyy。您可使用任何非数值的字符作为月份、日子与年份之
间的分隔符。您可将年份表达为四位数字(2007),或为两位数值(07)。
当您使用非缺省的语言环境,
且未设置 DBDATE 或 GL_DATE 环境变量时,
rstrdate()
使用客户机语言环境定义的日期终端用户格式。
当您在日期字符串中使用两位数字年份时,
rstrdate() 函数使用 DBCENTURY 环境变
量的值来确定要使用哪个世纪。
如果您未设置 DBCENTURY,
则 rstrdate() 为两位年份假
定第 20 世纪。
返回代码
0
转换成功。
< 0
转换失败。
-1204
inbuf 参数指定无效的年份。
-1205
inbuf 参数指定无效的月份。
-1206
inbuf 参数指定无效的日子。
-1212
数据转换格式必须包含月份、日子或年份组件。DBDATE 指定数据转换格式。
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 907 -
-1218
由 inbuf 参数指定的日期未正确地表示日期。
示例
demo 目录在 rstrdate.ec 文件中包含此样例程序。
/*
* rstrdate.ec *
The following program converts a character string
in "mmddyyyy" format to an internal date format.
*/
#include
main()
{
int4 i_date;
mint errnum;
char str_date[15];
printf("RSTRDATE Sample ESQL Program running.\n\n");
/* Convert Sept. 6th, 2007 into i_date */
if ((errnum = rstrdate("9.6.2007", &i_date)) == 0)
{
rfmtdate(i_date, "mmm dd yyyy", str_date);
printf("Date '%s' converted to internal format\n" str_date);
}
else
printf("rstrdate() call failed with error %d\n", errnum);
printf("\nRSTRDATE Sample Program over.\n\n");
}
GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 908 -
输出
RSTRDATE Sample ESQL Program running.
Date 'Sep 06 2007' converted to internal format
RSTRDATE Sample Program over.