简体   繁体   中英

Date format issue in SSRS

I have an issue with date format in my SSRS. I am saving date from DateTimePicker to database. From there I am taking display in my datagridview using following

dgv.items(0,2).value=Format(Cdate(dsSaver.tblInv.rows(0).items(0)),"dd-MMM-yyyy")

This displays it correctly (04-Nov-2011) but when I take date from the same database to my SSRS using

="Dated: " &Format(cdate(Fields!InvDate.Value),"dd-MMM-yyyy")

It displays it like 11-Apr-2011.

I have tested all winforms fare displaying it right but all SSRS are displaying it wrong. Please advise.

A couple of things are going on here. The date is being saved appropriately but is being displayed incorrectly due to your formatting options. This line is quite problematic:

="Dated: " & Format(cdate(Fields!InvDate.Value), "dd-MMM-yyyy") 

CDate takes a value, generally a string, and converts it to a date, which you are then taking and formatting back into a string. Now, by default reports are set to have their Language property set to English (United States) so the CDate function is taking the string representation of the date 04-Nov-2011 to be 04/11/2011 which it is then converting, using the US format of MM-dd-yyyy (not the Pakistani one) into being the date 11-Apr-2011 because it thinks the month comes first.

So, you should change your Language setting of your report to =User!Language so that it supports whatever the user's language is and will format things appropriately. This may be enough to make your expression work.

Regardless, if Fields!InvDate.Value is being supplied as a date field (as it should be) there is no need for the CDate function and this should work:

="Dated: " & Format(Fields!InvDate.Value, "dd-MMM-yyyy") 

There is also the FormatDateTime function but unfortunately it doesn't support the format you want to use.

您是否看过RDLC的“ 格式化报告”选项:“格式化日期”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM