水晶报表 - 如何从字符串中提取日期 [英] crystal reports - how to extract a date from string

查看:1667
本文介绍了水晶报表 - 如何从字符串中提取日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Crystal Reports 2008,我需要从文本字段中提取日期。此日期通常格式为dd / mm / yy,但也可以输入为d / m / yy,dd / m / yyyy等。

Using Crystal Reports 2008, I need to extract a date from a text field. This date is usually in the format dd/mm/yy, but could also be entered as d/m/yy, dd/m/yyyy, etc.

此日期可以出现在字符串中的任何位置。

This date could appear anywhere within the string.

目前我依赖的事实是,日期放在字符串的结尾,没有后面的fullstop,并使用LEFT / RIGHT提取每个日期部分。然后将这些部分传递给另一个公式以创建完整日期:

At the moment I am relying on the fact that the date is placed at the end of the string, without a following fullstop, and using LEFT/RIGHT to extract each date part. These parts are then passed to another formula to create a full date:

Dim AllocationDate()as Date
如果不是(IsNull({Command.Notes}) )then
Formula = DateValue((ToNumber({@Year})),(ToNumber({@Month})),(ToNumber({@Day})))

Dim AllocationDate() as Date If Not(IsNull({Command.Notes})) then Formula = DateValue ((ToNumber ({@Year})), (ToNumber ({@Month})), (ToNumber ({@Day})))

但是,如果任何人使用格式的变体,则在整个报告结束的日期之后添加一个或多个注释。

However, if anyone uses a variation of format, adds a fullstop or more notes after the date the whole report keels over.

有任何方式可以通过寻找模式提取这个日期?我想我可以使用TRIM来解决格式不一致的问题。

Is there any way I could extract this date by looking for a pattern? I'm guessing I could the use TRIM to get around the inconsistencies in format.

tyvmia

推荐答案

作为最后的手段,您可以尝试通过替换表示CR,LF等的特殊字符将多行字符串转换为长字符串。用空格或其他无害字符替换它们,然后将结果字符串视为只是一个常规字符串(日期在中间)。

And, as a last resort, you can try converting the multi-line string into a long string by replacing the special characters that represent CR, LF, etc. Replacing them with spaces or another innocuous character, and then treat the resultant string as if it were just a regular string (with the date in the middle).

您仍然必须做出一些假设:使每个字符串有一个日期,所有特殊字符都是已知的(或者您必须测试所有可能的特殊字符) ,日期有一致符合格式等。

You would still have to make some assumptions to make this possible: ONE date per string, all special characters are known (or you have to test for all possible special characters), the date has SOME conformity to the format, etc.

这篇关于水晶报表 - 如何从字符串中提取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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