如何修复我的日期公式

时间:2016-06-15 19:49:44

标签: crystal-reports

我的数据是CYYMMDD,我使用下面的当前公式。当字段的日期实际为0/00/00时,它会以Crystal为0.00,然后当我的公式转换为它时,它显示为11/30/99。如何将其显示为N / A?

Local StringVar x := ToText({FIELD}, "0");
Local NumberVar c := (ToNumber(LEFT(x, 1)) + 1) * 10;
x := RIGHT(x, 6);
Local NumberVar y := ToNumber(ToText(c, "0") & LEFT(x, 2));
x := RIGHT(x, 4);
Local NumberVar m := ToNumber(LEFT(x, 2));
x := RIGHT(x, 2);
Local NumberVar d :=ToNumber(x);

Dateserial(y,m,d)

1 个答案:

答案 0 :(得分:1)

试试这个:

namespace Sample.Tests
{
    using System;
    using System.Collections;
    using System.Collections.Immutable;
    using System.Collections.ObjectModel;
    using System.Linq;
    using System.Reflection;
    using Xunit;

    public class ImmutabilityTests
    {
        [Fact]
        public void CollectionCanBeConvertedToImmutable()
        {
            var original = new Collection<object>() { 1, 2, 3, 4, };
            var result = original.AsImmutable(typeof(int));

            Assert.NotEmpty(result);
            Assert.IsAssignableFrom<ImmutableList<int>>(result);
        }
    }

    public static class ReflectionExtensions
    {
        public static IEnumerable AsImmutable(this IEnumerable collection, Type elementType)
        {
            var immutableType = typeof(ImmutableList<>).MakeGenericType(elementType);
            var addRangeMethod = immutableType.GetMethod("AddRange");
            var typedCollection = ToTyped(collection, elementType);

            var emptyImmutableList = immutableType.GetField("Empty").GetValue(null);
            emptyImmutableList = addRangeMethod.Invoke(emptyImmutableList, new[] { typedCollection });
            return (IEnumerable)emptyImmutableList;
        }

        private static object ToTyped(IEnumerable original, Type type)
        {
            var method = typeof(Enumerable).GetMethod("Cast", BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(type);
            return method.Invoke(original, new object[] { original });
        }
    }
}

编辑---------------------------------------------- ---------

if database.field=0.0
then "N/A"
else
Local StringVar x := ToText({FIELD}, "0");
Local NumberVar c := (ToNumber(LEFT(x, 1)) + 1) * 10;
x := RIGHT(x, 6);
Local NumberVar y := ToNumber(ToText(c, "0") & LEFT(x, 2));
x := RIGHT(x, 4);
Local NumberVar m := ToNumber(LEFT(x, 2));
x := RIGHT(x, 2);
Local NumberVar d :=ToNumber(x);

ToText(Dateserial(y,m,d))