Doubt with Date Formatting in sql server 2008

Asked

Viewed 53 times

1

In my application I am recording 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 a query 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 the getdate will bring me this result:

select  CONVERT(datetime, getdate())

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

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

1 answer

1


Try it this way:

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)

  • 1

    Right answer, immensely grateful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.