public static DbValue FORMAT(DbFunctionTools tools, DbFunctionArguments args) { string FunctionName = "FORMAT"; args.EnsureCount(FunctionName, 2); DbType arg0type; ByteSlice arg0 = args[0].Eval(out arg0type); DbType arg1type; ByteSlice arg1 = args[1].Eval(out arg1type); if (Types.IsNullValue(arg0)) { return(tools.AllocNullValue()); // Give a null, take a null. } if (arg0type.ID != DbTypeID.CHARS) { args.Expected(FunctionName, 0, "input CHAR(n), got " + arg0type.Name.ToUpper()); } if (Types.IsNullValue(arg1)) { return(tools.AllocNullValue()); // Give a null, take a null. } if (arg1type.ID != DbTypeID.DATETIME) { args.Expected(FunctionName, 0, "input DATETIME, got " + arg1type.Name.ToUpper()); } string formatstr = tools.GetString(arg0).ToString(); DateTime dt = tools.GetDateTime(arg1); mstring result = mstring.Prepare(dt.ToString(formatstr)); while (result.Length < 80) { result.MAppend('\0'); } return(tools.AllocValue(result)); }