September 10, 2008 at 4:44 am
I have at a table whihc for export purposes to an accounting software needs to have the invoice date in a dd/mm/yyyy format, which is not a problem. But for the purposes of reports, I really need the date in a mm/dd/yyyy format. I attempted to do a datepart and concatenate in the correct order, but get an out of range error. What am I missing?
Thank you!
September 10, 2008 at 4:50 am
The CONVERT function offers lots of different data styles. See Books Online for details.
[font="Verdana"]Markus Bohse[/font]
September 10, 2008 at 5:07 am
chad_hainline (9/10/2008)
I have at a table whihc for export purposes to an accounting software needs to have the invoice date in a dd/mm/yyyy format, which is not a problem. But for the purposes of reports, I really need the date in a mm/dd/yyyy format. I attempted to do a datepart and concatenate in the correct order, but get an out of range error. What am I missing?Thank you!
What datatype is your invoice date?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
September 10, 2008 at 5:27 am
The original format is a varchar. I attemmpted to do a Convert(varchar,date,101) earlier, but the results came back unchanged.
September 10, 2008 at 5:32 am
If it's varchar then this would do the trick:
[font="Courier New"]DROP TABLE #Test
CREATE TABLE #Test (mmddyyyy VARCHAR(10))
INSERT INTO #Test
SELECT '01/01/2008' UNION ALL
SELECT '31/01/2008' UNION ALL
SELECT '01/02/2008' UNION ALL
SELECT '28/02/2008'
SELECT mmddyyyy,
SUBSTRING(mmddyyyy,4,2) + '/' + SUBSTRING(mmddyyyy,1,2) + '/' + RIGHT(mmddyyyy,4) AS ddmmyyyy
FROM #Test
[/font]
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
September 10, 2008 at 8:21 am
Thank you very much! Worked like a charm!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply