How to convert datetime format to date format in crystal report using C#?

好久不见. 提交于 2019-12-19 01:24:12

问题


i am working c# windows form application and also in crystal report.i am retriving the date from database in datetime format but i like display date only in report,Is any formula field in crystal report help for me for this problem.Thanks in Advance.


回答1:


If the datetime is in field (not a formula) then you can format it:

  1. Right click on the field -> Format Editor
  2. Date and Time tab
  3. Select date/time formatting you desire (or click customize)

If the datetime is in a formula:

ToText({MyDate}, "dd-MMM-yyyy")
//Displays 31-Jan-2010

or

ToText({MyDate}, "dd-MM-yyyy")
//Displays 31-01-2010

or

ToText({MyDate}, "dd-MM-yy")
//Displays 31-01-10

etc...




回答2:


In crystal report formulafield date function aavailable there pass your date-time format in that You Will get the Date only here

Example: Date({MyTable.dte_QDate})




回答3:


In case the formatting needs to be done on Crystal Report side.

Simple way.

Crystal Report Design Window->Right click on the date field->format Field->Customize the date format per your need.

Works effectively.




回答4:


In selection formula try this

Date(Year({datetimefield}), Month({datetimefield}), Day({datetimefield}))



回答5:


This formula works for me:

// Converts CR TimeDate format to AssignDate for WeightedAverageDate calculation.

Date( Year({DWN00500.BUDDT}), Month({DWN00500.BUDDT}), Day({DWN00500.BUDDT}) ) - CDate(1899, 12, 30)



回答6:


if it is just a format issue use ToShortDateString()




回答7:


Sometimes the field is not recognized by crystal reports as DATE, so you can add a formula with function: Date({YourField}), And add it to the report, now when you open the format object dialog you will find the date formatting options.




回答8:


There are many ways you can do this. You can just use what is described here or you can do myDate.ToString("dd-MMM-yyyy"); There are plenty of help for this topic in the MSDN documentation.

You could also write you own DateExtension class which will allow you to go something like myDate.ToMyDateFormat();

    public static class DateTimeExtensions
    {
        public static DateTime ToMyDateFormat(this DateTime d)
        {
            return d.ToString("dd-MMM-yyyy");
        }
    }


来源:https://stackoverflow.com/questions/3262464/how-to-convert-datetime-format-to-date-format-in-crystal-report-using-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!