0

I want to do the correct way to get a date from a @parameter that contains the complete datetime, that user gets from a calendar from TFS File.

In the select I would want to use something like CONVERT(varchar(10), @FechaHasta.Value, 120) AS DATE01 and then get the only date, throwing out the time from the parameter.


For the next step, I would want to compare it with another date in WHERE clause, having this code :

Awful code

Then, I would want to make this work on for looking for between two dates, and the last one, throwing out the time from the datetime.

Thanks.

Hogan
  • 69,564
  • 10
  • 76
  • 117
juannmcc
  • 109
  • 1
  • 1
  • 12
  • 2
    possible duplicate of [How to return the date part only from a SQL Server datetime datatype](http://stackoverflow.com/questions/113045/how-to-return-the-date-part-only-from-a-sql-server-datetime-datatype) – Hogan Oct 28 '14 at 17:18

1 Answers1

1

I am assuming @FetchHasta is a datetime

CONVERT(VARCHAR(10), @FetchHasta, 101)

is what gets you just the date part. i.e. 10/28/2014 1:10 PM would simply become 10/28/2014.

Source

EDIT: Alternatively, How to return the date part only from a SQL Server datetime datatype

Community
  • 1
  • 1
Scott T
  • 283
  • 1
  • 11
  • yes, but then, I put the '... AS date01' and compare in the where clause like that name? – juannmcc Oct 29 '14 at 08:26
  • No. You can put the `AS date01` for the column name if you wanted, but you would have to redo the calculation in the `WHERE` clause. It may be better to add a new variable before your `SELECT` query with the above calculation so you can use that in both places instead of calculating it repeatedly. – Scott T Oct 29 '14 at 12:07