Reputation: 138
This is not a question although, just a query.
While I was playing with SQL queries, I found something I was unable to know how it was happening.
I used the following query:
select Replace(getdate(),'-','')
And I got a result like
May 9 2014 4:51PM
Now, I thought to change the query to:
Select REPLACE(Getdate(),'-','/')
or used any other character in place of '/', I got the same output.
Would appreciate if someone could explain how this was happening. And yes, one more thing, could you please guide me how to format the question too, since I know this question's gonna need formatting after I have posted it...:P
Upvotes: 0
Views: 725
Reputation: 10264
Replace function has a definition as:
REPLACE ( string_expression , string_pattern , string_replacement )
where
Now what's happening here is Getdate() returns current date as a datetime
datatype which is implicitly converted to varchar or to say a string expression to evaluate the function. Try casting getdate() to varchar as below and you should get your confusion resolved:
select CAST( getdate() AS nvarchar(25))
You can read more about Implicit conversions here: http://msdn.microsoft.com/en-us/library/ms187928.aspx
Upvotes: 2
Reputation: 28741
REPLACE() function is converting datetime value to string representation of date
Upvotes: 2