[英]How to convert datetime format to date format in crystal report using C#?
我正在使用c#windows窗体应用程序,也在水晶报表中。我正在从数据库中以datetime格式重新审核日期,但我只想在报告中显示日期,水晶报告中的任何公式字段都对我有帮助。这个问题谢谢。
If the datetime is in field (not a formula) then you can format it: 如果日期时间在字段中(不是公式),那么您可以格式化它:
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... 等等...
In crystal report formulafield date function aavailable there pass your date-time format in that You Will get the Date only here 在水晶报表公式字段日期函数aavailable中传递您的日期时间格式,您将在此处获取日期
Example: Date({MyTable.dte_QDate})
示例:
Date({MyTable.dte_QDate})
In case the formatting needs to be done on Crystal Report side. 如果需要在Crystal Report端进行格式化。
Simple way. 简单的方法。
Crystal Report Design Window->Right click on the date field->format Field->Customize the date format per your need. Crystal Report设计窗口 - >右键单击日期字段 - >格式字段 - >根据需要自定义日期格式。
Works effectively. 有效地工作。
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)
在选择公式中试试这个
Date(Year({datetimefield}), Month({datetimefield}), Day({datetimefield}))
有时字段不会被水晶报表识别为DATE,因此您可以添加一个带有函数的公式:Date({YourField}),并将其添加到报表中,现在当您打开格式对象对话框时,您会发现日期格式选项。
如果它只是一个格式问题使用ToShortDateString()
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");
您可以使用此处描述的内容,也可以执行
myDate.ToString("dd-MMM-yyyy");
There are plenty of help for this topic in the MSDN documentation. MSDN文档中有很多关于此主题的帮助。
You could also write you own DateExtension class which will allow you to go something like myDate.ToMyDateFormat();
您也可以编写自己的DateExtension类,它允许您使用
myDate.ToMyDateFormat();
public static class DateTimeExtensions
{
public static DateTime ToMyDateFormat(this DateTime d)
{
return d.ToString("dd-MMM-yyyy");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.