以24小时格式解析日期时间 [英] parsing date time in 24 hour format

查看:96
本文介绍了以24小时格式解析日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

i确实要求将24小时格式的日期时间传递给sql server中的storedprocedure。

我写的如下: -

DateTime fromdate = DateTime.Now;

DateTime todate = DateTime.Now.AddDays(-5);

这些是给o / p as

8-06-2015 12:00:00和3-06-2015 12:00:00

但我需要通过作为存储过程

2015-06-08 00:00:01和2015-06-03 23:59:59

i有搜索了许多网站但无法找到与我的要求完全匹配的PLZ帮我解决这个问题....

先谢谢。

解决方案

你有一个关于日期/时间的基本错误...你认为由于某种原因,日期/时间是你看到的,但实际上日期/时间是一个二进制值存储完全相同但格式化显示不同...

因此,当您想在SQL中记录日期/时间时,请为列选择正确的数据类型(并且不要!strin g)并按原样传递日期/时间(二进制) - SQL将处理其余的事情!!!


几天前查看这些解决方案类似的问题=> ; 对使用SQL数据类型感到困惑 [< a href =http://www.codeproject.com/Answers/998036/Confused-about-using-SQL-data-type?arn=0#answer2target =_ blanktitle =New Window> ^

Dear all,
i do have a requirement that to pass datetime in 24 hour format to a storedprocedure in sql server.
for that i have written as follows:-
DateTime fromdate=DateTime.Now;
DateTime todate=DateTime.Now.AddDays(-5);
these are giving o/p as
8-06-2015 12:00:00 and 3-06-2015 12:00:00
But i need to pass to an stored procedure as
2015-06-08 00:00:01 and 2015-06-03 23:59:59
i have searched many sites but unable to find exact matching to my requirement plz help me solve this....
Thanks in Advance.

解决方案

You have a basic mistake about date/time...You think for some reason that date/time is what you see, but actually date/time is a binary value stored exactly the same but formatted for display differently...
So when you want to sore date/time in SQL choose the proper data type for the column (and NOT! string) and pass the date/time as is (binary) - SQL will take care of the rest!!!


Check out these solutions to a similar question just a few days ago => Confused about using SQL data type[^]


这篇关于以24小时格式解析日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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