Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get just the date part of getdate()? [duplicate]

I have a SQL table that has a CreationDate field.

I have getdate() in the computed column specification formula.

I would like to know how to get just the date portion, that is, '2012-08-24' instead of '2012-08-24 10:45:17.740'.

like image 442
Rui Martins Avatar asked Aug 24 '12 08:08

Rui Martins


People also ask

How do I extract just the day from a date in sql?

If you want to get a day from a date in a table, use the SQL Server DAY() function. This function takes only one argument – the date. This can be a date or date and time data type. (In our example, the column VisitDate is of the date data type.)

How do I get the date part of a timestamp?

In order to get the date from the timestamp, you can use DATE() function from MySQL.


1 Answers

If you are using SQL Server 2008 or later

select convert(date, getdate()) 

Otherwise

select convert(varchar(10), getdate(),120) 
like image 172
podiluska Avatar answered Oct 02 '22 17:10

podiluska