从日期字段中删除时间部分 [英] remove time part from date field

查看:97
本文介绍了从日期字段中删除时间部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将文本框中的日期插入到没有时间的datetime字段中

我有带ajax日历的textbox1,并且当我必须将选择的日期插入datetime字段中时

插入值为4/5/2011 12:00:00
我不希望时间部分

how to insert date from text box into datetime field without time

i have textbox1 with ajax calendar and when i have to insert selected date into datetime field

the inserted value is 4/5/2011 12:00:00
i don''t want the time part

推荐答案

您可以在客户端进行格式化,也可以将其嵌入到SQL语句中.例如,当前日期为:
You can make the formatting at client side or you can embed it to the SQL statement. For example current datetime to date would be:
SELECT CAST(GETDATE() AS DATE)


如果您查看^ ]在MSDN上并检查代码,您会发现以下内容:
If you look at this page[^] on MSDN and examinr the code, you will find this:
<asp:BoundField HeaderText="Price/Unit"

   DataField="UnitPrice" SortExpression="UnitPrice"

   DataFormatString="{0:c}">


该代码会格式化单价"列中的数据.

毫不奇怪,您可以对日期和货币执行类似的操作.
此页面上 [


that code formats the data for the ''Unit Price'' column.

Unsurprisingly you can do a similar thing for Dates as well as for Currency.
On this page[^] you will find the various Format Characters and the second table lists those for date values. The first one is the one you would need.


这篇关于从日期字段中删除时间部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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