Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove time from DateTime sql server 2005

I need date part from datetime. in format of "dd-mm-yyyy"

I have tried follwoing

Query:

select Convert(varchar(11), getdate(),101)

Output:

01/11/2011

Query

SELECT cast(floor(cast(GETDATE() as float)) as datetime)

Output

2011-01-11 00:00:00.000

Query:

SELECT 
    CONVERT(VARCHAR(MAX),DATENAME(DD,GETDATE())) + '-' + 
    CONVERT(VARCHAR(MAX),DATEPART(MONTH,GETDATE())) + '-' + 
    CONVERT(VARCHAR(MAX),DATENAME(YYYY,GETDATE())) `

Output:

11-1-2011 i.e. "d-m-yyyy"

I required output in "dd-mm-yyyy" format.

like image 879
Mike Avatar asked Jan 11 '11 13:01

Mike


2 Answers

SELECT CONVERT(VARCHAR(10),GETDATE(),105)
like image 161
Lamak Avatar answered Sep 24 '22 03:09

Lamak


Try:

SELECT convert(varchar, getdate(), 105)

More here.

like image 29
eumiro Avatar answered Sep 20 '22 03:09

eumiro