如何将日期时间值转换为日期

如何将日期时间值转换为日期

本文介绍了如何将日期时间值转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中有一个datetime值.我需要将日期作为查询字符串传递,所以我想通过使用convert函数将datetime转换为date.
这是我的代码

I have a datetime value in database.i need to pass date as querystring so i want to convert the datetime into date by using convert function.
here is my code

SqlCommand comm1 = new SqlCommand("select distinct trackorder,netprice,recip_name,bill_name,convert(varchar,date,103) from tbl_trackorder join tbl_users_products on tbl_trackorder.usersess=tbl_users_products.usersession join tbl_recipient on tbl_users_products.usersession=tbl_recipient.usersession join tbl_billing on tbl_recipient.usersession=tbl_billing.usersession join tbl_session_user on tbl_session_user.usersession=tbl_recipient.usersession  and tbl_session_user.usersession=tbl_billing.usersession where tbl_session_user.date='"+date+"'", sqlcon);
        SqlDataAdapter dap = new SqlDataAdapter();
        dap.SelectCommand = comm1;
        DataSet dss = new DataSet();
        dap.Fill(dss);
        return dss;


它将返回错误:The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

谁能帮我.

谢谢


it will return a error:The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

can any one help me.

Thanks

推荐答案



这篇关于如何将日期时间值转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 08:22