Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql Server select datetime without seconds

I have datetime column value below

2015-01-04 20:37:00.000

I tried below

cast(cast(MyDateColumn as date) as datetime)+cast(datepart(hour,MyDateColumn ) as float)/24
as MyDateColumn 

and

CAST(CONVERT(CHAR(16),MyDateColumn,113) AS datetime) as MyDateColumn

These are did not work for me

How can i get above datetime as 01-04.2015 20:37 ?

like image 572
Soner Sevinc Avatar asked Jan 13 '15 08:01

Soner Sevinc


People also ask

How can I get time without seconds in SQL?

How can I get time without seconds in SQL? it is always stored the only thing you can do is to edit the value before it gets posted so the seconds (and also the milliseconds which are also stored) are set to 0. I suggest you to use two columns for: Hour & Minute ;).

How can I get only time from DateTime in SQL?

How do you get just the time from a DateTime in SQL? SELECT GETDATE();– Output: 2019-03-31 08:12:08.600. SELECT CAST('2019–03–31 08:12:08.600' AS TIME)– Output: 08:12:08.6000000. SELECT CONVERT(VARCHAR(10), CAST('2019–03–31 08:12:08.600' AS TIME), 0)– Output: 8:12AM.

How do I select only the date in SQL?

Use CASTSELECT CAST(getdate() AS date);


1 Answers

Since MS SQL 2012, you can use FORMAT,

SELECT FORMAT([MyDateColumn], 'dd-MM.yyyy HH:mm') 
like image 198
Jodrell Avatar answered Sep 20 '22 06:09

Jodrell