Search code examples
c#asp.netdatetimeteleriktelerik-reporting

Empty datetime in the report


I face the following problem :

Sometimes the value of my trans_in(DateTime) in my database is :1900-01-01 00:00:00.000

and it appears in my telerik report like this 12:00 AM i want to show the textbox empty instead so i create the following custom method :

  public static string NotAttend(DateTime trans_in)
        {
            if (trans_in == null || trans_in.ToString().Trim() == "1900-01-01 00:00:00.000")
            {
                return string.Empty;
            }
            else
                return trans_in.ToShortTimeString();
        }

and bind the textbox like this :

= OvertimeReports.CustomExpressions.NotAttend(Fields.trans_in)

but this didn't fix my problem still appear 12:00 AM !!


Solution

  • Your trans_in.ToString() would return you the string representation of your DateTime object based on your current culture, its better if you check your DateTime like:

    public static string NotAttend(DateTime trans_in)
    {
       if(trans_in == new DateTime(1900, 1, 1))
       {
            return string.Empty;
       }
        else
            return trans_in.ToShortTimeString();
    }