AS400数字日期字段为标准日期格式VB.Net自定义功能 [英] AS400 Numeric Date Field to Standard Date Format VB.Net Custom Function

查看:390
本文介绍了AS400数字日期字段为标准日期格式VB.Net自定义功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的代码项目,
我正在尝试为我的报表服务编写一个简单的代码功能,该功能基本上是将数字转换为日期.请参见下面的代码:
但是,我的表中也有一些空行,因此当我使用以下代码运行报表时,我得到一些行有错误([rsRuntimeErrorInExpression]字段'aaa'的Value表达式包含错误:索引和长度必须引用字符串中的位置.
参数名称:length),我该如何修复我的代码?
谁能帮我吗?
VT

公共函数ConvertDate(ByVal值作为字符串)作为日期

''将YYYYMMDD格式的日期转换为DD/MM/YYYY格式.

暗淡化为字符串= value.SubString(0,4)
将MonthMonth作为String = value.SubString(4,2)
Dim theDay As String = value.SubString(6,2)
结果暗淡为String = theDay&"/"&theMonth&"/"&theYear
返回CDate(结果)
结束函数

Dear The Code Project,
I am trying to write a simple code function for my reporting services, which is basically converting number to date. please see below for the code:
However i have also some empty rows in my table, so when i runt the report with the following code i get some rows have Error ([rsRuntimeErrorInExpression] The Value expression for the field ‘aaa’ contains an error: Index and length must refer to a location within the string.
Parameter name: length), how can i fix my code?
Can anyone help me?
VT

Public Function ConvertDate(ByVal value As String) As Date

'' Converts a date in YYYYMMDD format to DD/MM/YYYY format.

Dim theYear As String = value.SubString(0, 4)
Dim theMonth As String = value.SubString(4, 2)
Dim theDay As String = value.SubString(6, 2)
Dim result As String = theDay & "/" & theMonth & "/" & theYear
return CDate(result)
End Function

推荐答案

为什么不使用DateTime.TryParseDateTime.TryParseExact?

这将帮助您通过一行代码摆脱该功能.
Why are you not using DateTime.TryParse or DateTime.TryParseExact?

That would help you getting rid of this function by one line of code.


这篇关于AS400数字日期字段为标准日期格式VB.Net自定义功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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