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.

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

yes, but then, I put the '... AS date01' and compare in the where clause like that name?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.