在Crystal Reports中将字符串转换为日期 [英] Convert string to date in Crystal Reports

查看:108
本文介绍了在Crystal Reports中将字符串转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Crystal报表中将字符串值转换为日期。如您所知,Crystal在精选专家中很方便。但是,如果不进行转换,我将无法使用它。该字符串只有四个字符(示例:0512),因为没有日期或年份的全值,所以我无法使用日期值功能。任何帮助,将不胜感激!

I need to convert a string value to a date in a crystal report. As you know Crystal has a handy "in the period of" in the select expert. However I am unable to use it without converting. The string is only four characters (example: 0512) I am having trouble using the date value function since there is no day or a full value for the year. Any help would be appreciated!

推荐答案

只需将字符串处理为正确的格式并使用CDate函数。看来日期对您而言并不重要,因此将其设置为每月的第一天。

Just manipulate the string into the proper format and use the CDate function. It doesn't look like the day number matters to you, so set it to the first of the month.

假设0512表示2012年5月,您的代码应类似于

Assuming that 0512 means May 2012 your code should look something like this:

CDate('01' + '/' + Left({DateObject},2) + '/' + '20' + Right({DateObject},2))

返回日期1/5 / 12使用您的样本值。然后,您可以根据需要设置其格式。

That returns a date of 1/5/12 using your sample value. You can then format it as needed.

这篇关于在Crystal Reports中将字符串转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆