Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am working on .rdlc reports.I have a date column in the report .
I am formating date column using the expression
=Format(Fields!Date.Value,"yyyy/MM/dd" & " " & "h:mm:ss tt").
It is working fine in one report.It is displaying the datetime correctly example:
VB
2011/01/18 9:53:17 AM
.
But it is not working in other report.It is displaying the value in the column as yyyy/MM/dd h:mm:ss tt

Thanks in advance
Posted
Updated 11-Dec-18 8:12am
Comments
Mario Majčica 22-Aug-11 8:33am    
Can you be more specific? What troubles you precisely?

1 solution

Probably there is something wrong with Fields!Date.Value.

Try something similar:

C#
DateTime dateValue;

if (DateTime.TryParse(Fields!Date.Value, out dateValue))
    return dateValue.ToString("yyyy/MM/dd h:mm:ss tt")
else
    return "n/a";


Let us know!

Cheers


EDIT:

I just tried the following code:
string printableString;
DateTime dateValue;

if (DateTime.TryParse("22-08-2010 14:57:33", out dateValue))
    printableString = dateValue.ToString("yyyy/MM/dd h:mm:ss tt");
else
    printableString = "n/a";


And the result is 2010-08-22 2:57:33 as expected.

If I try to enter the wrong input as DateTime.TryParse("25-25-2010 14:57:33", out dateValue)
I get n/a as the result.

If you show me some more code, maybe we can find a proper solution.

Bye
 
Share this answer
 
v2
Comments
neha427 22-Aug-11 8:51am    
Hi Mario,
I am trying to use your expression.
But I am getting an error that "TryParse" is an unrecognized identifier.
Thanks
Mario Majčica 22-Aug-11 9:02am    
Check the edit.
neha427 22-Aug-11 9:16am    
Hi Mario,
My Report has 4 columns : Record Type,Description,Account Number,Date.
I created a dataset and I pulled the fields to the report from the dataset.
Now I am trying to format the Date column to 2010-08-22 2:57:33.
I am just trying to write the expression to format the date in the value field.
I did this and it worked fine in one of my previous report.
Now I am trying to format the same date field in other report.But it is not working.It is diaplaying as yyyy/MM/dd h:mm:ss tt
Mario Majčica 22-Aug-11 9:19am    
What it seems to be the problem is in your data feed. Check the content of your DataSet and see if there is any invalid DateTime value. You can do the check using the code I provided or by setting up a brake point inside your code.
neha427 22-Aug-11 9:36am    
There is no invalid date time.
Every thing looks fine.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900