now()函数存储DD / MM / YYYY [英] now() function store DD/MM/YYYY

查看:89
本文介绍了now()函数存储DD / MM / YYYY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用now()函数插入查询时,它会抛出DD / MM / YYYY,但需要将MM / DD / YYYY发送到数据库。





它发生在Windows Server 2012中。



我在想什么时区问题,但我需要改变的地方我没有得到一些解决方案。

When inserting query using now() function it is throwing DD/MM/YYYY but need to send MM/DD/YYYY to database.


It is happen in windows server 2012.

What i am thinking time zone problem but where i need to change i am not getting give some solution.

推荐答案

在将日期发送到数据库之前不要格式化日期:通过参数化查询作为DateTime对象发送它们(如DateTime.Now返回)并将其存储在数据库作为DateTime列。

这样,你可以对它进行比较,一切都会正常工作。您只应在实际需要向用户显示日期时格式化日期,然后您应该使用他喜欢的显示格式。
Don't format dates before sending them to a database: send them via a parameterised query as a DateTime object (as DateTime.Now returns) and store it in the DB as a DateTime column.
That way, you can do comparisons on it and everything will just work. You should only format dates when you actually need to present them to the user, and you should be using his prefered display format then anyway.


使用下面的代码行来格式化日期。

DateTime time = DateTime.Now;

time.ToString(MM / dd / yyyy,CultureInfo.InvariantCulture);



还查看以下链接以获取更多信息



http://stackoverflow.com/questions/18595758/date-format-conversion-in-c-sharp [ ^ ]
Use below lines of code to format the date.
DateTime time = DateTime.Now;
time.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);

also check below link for more information

http://stackoverflow.com/questions/18595758/date-format-conversion-in-c-sharp[^]


这篇关于now()函数存储DD / MM / YYYY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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