简体   繁体   English

在Crystal Reports中将字符串转换为日期

[英]Converting string to date in Crystal Reports

I'm new to Crystal Reports, I'm trying to extract and display month and year from the string (In DB the data type of the column is varchar). 我是Crystal Reports的新手,我试图从字符串中提取并显示月份和年份(在DB中,列的数据类型为varchar)。 Following is an example of the data. 以下是数据示例。

05-JAN-12 11.49.28.000000000 AM 2012年1月5日上午11.49.28.000000000

I need it in following format 我需要以下格式

Jan-12 1月12日

I have used cDate to convert the string to date format but was unsuccessful, maybe I didn't do it right way. 我已经使用cDate将字符串转换为日期格式,但是没有成功,也许我做的方式不正确。

Alter the formula to extract the date portion, then convert it to a date : 更改公式以提取日期部分,然后将其转换为date

DateValue(Split("05-JAN-12 11.49.28.000000000 AM")[1])

Apply formatting to the field as desired. 根据需要将格式应用于字段。

This may work 这可能有效

Date (Year ({reportfield}) * 10000 + Month ({reportfield}) * 100 + Day ({reportfield}))

Then format the field to display the date as your choosing. 然后格式化该字段以显示日期作为您的选择。

MonthName(DatePart ("m", <<Date field>>))+"-"+totext(DatePart ("yyyy", <<DAtefield>>),0,"")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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