Sql server convert string to datetime

I have this line: '30 / 05/2010 'and I would like to enter it in the smallDatetime field. In the database, it should look something like this. 2010-05-30 15:33:25 Any idea how?

Ty

+3
source share
4 answers

using

select convert(smalldatetime,'30/05/2010',103)
+5
source
SET DATEFORMAT DMY 
SELECT CAST('30/05/2010' as smalldatetime)

Where do you need the time aspect? The conversion above will add 00:00 (midnight) for smalldatetime, because:

  • line has no time information
  • smalldatetime allows minute resolution
+1
source

datetime, 2010-05-30 15:33:25. , date.

0

cast('05/30/2010' as smalldatetime).

If you need accurate time 15:33:25, you can use several dateadd calls, for example. select dateadd(hh, 15, cast('05/30/2010' as smalldatetime))returns 2010-05-30 15:00:00.

0
source

Source: https://habr.com/ru/post/1747748/


All Articles