Quizzes & Puzzles8 mins ago
Concatenation of DATEPART functions
2 Answers
I am trying to concatenate DATEPART(day, Order_Date) from a given table with DATEPART(Month, GETDATE()) and DATEPART(Year, GETDATE()) but all the results I am getting so far have been 2041 which is of NO use whatsoever! Does anyone have an idea as to the code for this? It may well be ridiculously straightforward and I apologise for my ignorance if it is!
Answers
Best Answer
No best answer has yet been selected by TheUnderTow. Once a best answer has been selected, it will be shown here.
For more on marking an answer as the "Best Answer", please visit our FAQ.As you are using the GETDATE() function I am assuming you are using SQL server, you can't concatenate if the results are not strings
SELECT CAST(DATEPART(d,[Order_Date]) AS nvarchar(2)) + CAST(DATEPART(m,GETDATE()) AS nvarchar(2)) + '/' + CAST(DATEPART(y,GETDATE()) AS nvarchar(4)) FROM yourtablename
SELECT CAST(DATEPART(d,[Order_Date]) AS nvarchar(2)) + CAST(DATEPART(m,GETDATE()) AS nvarchar(2)) + '/' + CAST(DATEPART(y,GETDATE()) AS nvarchar(4)) FROM yourtablename
Related Questions
Sorry, we can't find any related questions. Try using the search bar at the top of the page to search for some keywords, or choose a topic and submit your own question.