Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i use convert(varchar,convert(date, [Date], 103),101) if data is not available on particular date this query is fetching next date data .

What I have tried:

convert(varchar,convert(date, [Date], 103),101)
Posted
Updated 11-Sep-16 22:50pm
Comments
Maciej Los 12-Sep-16 3:10am    
Really? Could you be so kind to provide example data to proof that your statement is true?
Member 12363094 12-Sep-16 4:34am    
yeah really when i have run above query in ssms it is coming well
but when i am running application there i am calling this sp at that time i am getting other date date if data is not on that date.
Member 12363094 12-Sep-16 4:35am    
again wen i change stored proc then i am able to download perfectly
Tushar sangani 12-Sep-16 3:31am    
heloo yuo use this formate to convert date

convert(varchar(10),[Date],101)

1 solution

when i use convert(varchar,convert(date, [Date], 103),101) if data is not available on particular date this query is fetching next date data .


Above statement is untrue!

SQL
SELECT convert(varchar,convert(date, null, 103),101) AS myDate
--returns: NULL

SELECT convert(varchar,convert(date, '', 103),101) AS myDate
--returns: 1900-01-01


For further details, please see: CAST and CONVERT (Transact-SQL)[^]
MS wrote:
When character data that represents only date or only time components is cast to the datetime or smalldatetime data types, the unspecified time component is set to 00:00:00.000, and the unspecified date component is set to 1900-01-01.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900