Doubt with Date formatting in sql server 2008

1

In my application I'm writing the dates in this format:

DateTime.Now.ToString("yyyy/MM/dd");

In the database I have: 2016-01-09 00:00:00.000

Now I need to make an appointment where I will bring only the records of the day.

select * from TB_JOGO where DATA_INC = CONVERT(datetime, DATA_INC)

Using a fixed date will bring me this result:

select  CONVERT(datetime, '2016-01-09')
  

Result: 2016-01-09 00: 00: 00,000

Using getdate will bring me this result:

select  CONVERT(datetime, getdate())
  

result: 2016-01-10 21: 57: 45.603

I need the date of the day in this format: 2016-01-09 00:00:00.000 using command getdate()

    
asked by anonymous 11.01.2016 / 01:09

1 answer

1

Try this:

select cast(getdate() as date) data

or

select  CONVERT(date, getdate()) data
  

date
  ----------
2016-01-10

     

(1 row (s) affected)

     

date
  ----------
2016-01-10

     

(1 row (s) affected)

    
11.01.2016 / 01:25