如何转换EN-GB为e​​n-US(算术溢出错误转换前pression数据类型DATETIME) [英] How to convert en-gb to en-us (Arithmetic overflow error converting expression to data type datetime)

查看:114
本文介绍了如何转换EN-GB为e​​n-US(算术溢出错误转换前pression数据类型DATETIME)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

算术溢出错误转换前pression数据类型日期时间。该语句已终止。

我的网站的文化是EN-GB(18/10/2010)

The culture of my site is en-gb (18/10/2010)

我的数据库服务器的文化是EN-US(10/18/2010)

The culture of my db server is en-us (10/18/2010)

的日期被存储在参数;

the date is stored in a param;

command.Parameters.AddWithValue("@bookingdate", inputBookingDate.Text)

有没有办法进入DB前,将其转换为美国日期格式?

Is there a way to convert this to US date format before entering into db?

我想这code;

    Dim dbDate As String = command.Parameters("@bookingdate").Value.ToString
    dbdate = DateTime.Parse(dbdate, New CultureInfo("en-US"))
    command.Parameters("@bookingdate").Value = dbdate

但得到错误的字符串未被识别为有效的DateTime。

dbDate = "29/10/2010 00:00:00" 

我如何指定当前的文化?识别DBDATE在GB格式的有效日期时间。

How do I specify the current culture? identifying dbDate as a valid datetime in GB format.

感谢。

推荐答案

尝试日期时间.Parse 。阅读在GB格式的日期,它在美国的格式写出来的。也是一个很好的时间来检查你的UI code,以确保它无处不在使用GB格式。或更改数据库预计的格式。

Try DateTime.Parse. Read in the date in GB format, write it out in US format. Also a good time to check your UI code to make sure it is using GB formatting everywhere. Or change the format your DB expects.

如果您的数据库支持的话,你可以写出来的日期为时间戳,试图尽量减少使用美国日期格式的次数。

If your DB supports it, you could write out the date as a timestamp to try and minimise the number of times you use the US date format.

这篇关于如何转换EN-GB为e​​n-US(算术溢出错误转换前pression数据类型DATETIME)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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