我该如何解决这条线? [英] How do I solve this line?

查看:113
本文介绍了我该如何解决这条线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

dateFrom = Convert.ToDateTime(dr["DateFrom"].ToString());



如何仅检索日期?


How do I retrieve as Date only?

推荐答案

所以,问题是 格式化 DateTime

只需在转换时明确指定格式字符串使用.ToString的字符串:

So, the problem is with formatting the DateTime?
Just specify the format string explicitly when converting to a string using .ToString:
string formattedDate = Convert.ToDateTime(dr["DateForm"].ToString()).ToString("dd/MM/yyyy");


如果您的SQL列数据类型是日期它将存储为01/01/2001(不包括时间戳)

如果是DateTime,它将包括日期和时间价值......


$ C $ b 在C#中

我们没有 日期 DataType ,我们只有 DateTime 这是的组合日期和时间

您只能以 string 格式获取日期值而不是 DateTime 对象。



使用SOlutoin 1获取字符串格式。

和实际日期时间的代码。



希望你理解。
如果你需要更多澄清,
会回来。





_________
Karthik


See , if your SQL Column DataType is Date it will store as "01/01/2001" (time stamp will not be included)
if it is DateTime it will include Date and Time values...

in C#
we dont have a Date DataType, we have only DateTime which is a combination of Date and Time
You can get the Date Value in string format only not the DateTime Object.

use SOlutoin 1 for Getting in string format.
and your code for actual DateTime.

Hope you understood.
come back if you need more clarification.


_________
Karthik



尝试

Try
dateForm = Convert.ToDateTime(dr["DateForm"]).Date;





希望这会有所帮助,

Fredrik



Hope this helps,
Fredrik


这篇关于我该如何解决这条线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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