如何将日期时间格式(dd/mm/yyyy hh:mm:ss转换为yyyy-mm-dd hh:mm:ss.000) [英] how to convert datetime format(dd/mm/yyyy hh:mm:ss to yyyy-mm-dd hh:mm:ss.000)

查看:201
本文介绍了如何将日期时间格式(dd/mm/yyyy hh:mm:ss转换为yyyy-mm-dd hh:mm:ss.000)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将dd/mm/yyyy hh:mm:ss转换为yyyy-mm-dd hh:mm:ss.000


我正在使用此-


convert(datetime,''dd/mm/yyyy hh:mm:ss'')

&

convert(varchar(24),''dd/mm/yyyy hh:mm:ss'',121)

都给我那个错误-
将char数据类型转换为datetime数据类型会导致超出范围的datetime值.

Hi i want to convert dd/mm/yyyy hh:mm:ss to yyyy-mm-dd hh:mm:ss.000


i am using this-


convert(datetime,''dd/mm/yyyy hh:mm:ss'')

&

convert(varchar(24),''dd/mm/yyyy hh:mm:ss'',121)

both gives me that error-
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

string totalDateStart = txtStartDate.Text.Trim() + " " + txtSHr.Text.Trim() + ":" + txtSMin.Text.Trim() + ":00" + " " + ddlAM1.SelectedValue; 
DateTime StrDate = Convert.ToDateTime(totalDateStart); 


我想检查是否输入了相同的时间.我正在使用此代码-

我得到开始日期.用户以dd/mm/yyyy hh:mm:ss格式插入.在数据库中,我使用startdate作为datetime格式,因此它会自动采用yyyy-mm-dd hh:mm:ss.000格式.
谢谢


i want to check whether the same time in time is entered or not. i am using this code-

i get startdate. user insert in dd/mm/yyyy hh:mm:ss format. and in database i use startdate as datetime format so it automatically take yyyy-mm-dd hh:mm:ss.000 format.

Thanks

推荐答案

尝试以下查询.它将dd/mm/yyyy hh:mm:ss 格式的字符串转换为yyyy-mm-dd hh:mm:ss.000
Try the below query. It converts a string in dd/mm/yyyy hh:mm:ss format to yyyy-mm-dd hh:mm:ss.000
DECLARE @DatetimeString VARCHAR(25) = '23/10/2016  10:12:12.000'

SELECT CONVERT(VARCHAR(24), CONVERT(DATETIME, @DatetimeString, 103), 121) Date


您得到的结果为


You get the result as

Date
------------------------
2016-10-23 10:12:12.000



但是对于您比较日期的方式,我仍然不是很确信.将日期和日期都转换为日期后,应该对日期进行比较.



But still I am not very convinced in the way in which you are comparing the dates. Dates should be compared after converting both to datetime.


使用此方法:
SELECT CONVERT(VARCHAR(23), GETDATE(), 121)


这篇关于如何将日期时间格式(dd/mm/yyyy hh:mm:ss转换为yyyy-mm-dd hh:mm:ss.000)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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