Example #1
0
        /// <summary>
        /// format a date in a form that will be adjusted
        /// for each database in FormatQueryRDBMSSpecific;
        /// (correct order of month/day etc)
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static TVariant FormatDate(TVariant value)
        {
            String list;
            String day;
            String month;
            String year;
            String resultString;

            if (value.TypeVariant == eVariantTypes.eDateTime)
            {
                resultString = "#" + value.DateToString("yyyy/MM/dd") + "#";

                // it seems, the separators (e.g. , /, .) are not considered
                resultString = resultString.Replace(value.DateToString("yyyy/MM/dd")[4], '-');
            }
            else
            {
                list = value.ToString();

                // try all available separators, defined in Ict.Common.StringHelper
                day = StringHelper.GetNextCSV(ref list, ".", true);

                if (list.Length == 0)
                {
                    throw new Exception("Ict.Petra.Server.MReporting.FormatQuery: Cannot decode date " + value.ToString());
                }

                month = StringHelper.GetNextCSV(ref list, ".", true);
                year = StringHelper.GetNextCSV(ref list, ".", true);

                resultString = String.Format("#{0:4}-{1:2}-{2:2}#",
                    year, month, day);
            }

            return new TVariant(resultString, true); // explicit string
        }