简体   繁体   English

如何在SQL和VB.net中将模糊日期转换为日期字段

[英]How to convert Fuzzy date as Date field in SQL and VB.net

I have a duedate field on a table which the datatype is Fuzzydate. 我在数据类型为Fuzzydate的表上有一个Duedate字段。 How to convert this to Date field in SQL and VB? 如何在SQL和VB中将其转换为Date字段?

For example the Duedate on backend is : Duedate = 20160531 and I wan to convert it as Duedate = 2016-05-31 例如后端的Duedate是:Duedate = 20160531,我想将其转换为Duedate = 2016-05-31

If this is always in the exact format you specified then you can use DateTime.ParseExact: 如果始终采用您指定的确切格式,则可以使用DateTime.ParseExact:

dateValue = DateTime.ParseExact("20160531", "yyyyMMdd", CultureInfo.InvariantCulture)

If it is in a number of different formats, you can use TryParseExact a number of times with different formats or just: 如果它采用多种不同的格式,则可以使用TryParseExact多次使用不同的格式,或者仅使用:

CDate()

Then to convert it to whatever date format you need: 然后将其转换为所需的任何日期格式:

dateValue.ToString("yyyy-MM-dd")

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

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