Discussion Locked

SQL Result Set Formatting

0 helpful
11 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have a SQL Result Set I want to format. It is a date being returned as 20010504 it is varchar(8). I want the result to look like 05/04/2001.

11 replies

by medievaldude

Try something like this:

Dim strMyDate
Dim strMyFormattedDate

strMyDate = rs("myDateField")
strMyFormattedDate = Mid(strMyDate, 5, 2) & "/" & Mid(strMyDate, 7, 2) & "/" & Left(strMyDate, 4)

At this point, strMyFormattedDate should appear as "05/04/2001" for the given example you provided.

by john_wills

As you work for the government, should you not be setting a good example by writing all your dates in ISO format, which SQL is giving you? The format you want is a protest against the Gregorian calendar, and it is really rather late for that.

by john_wills

As you work for the government, should you not be setting a good example by writing all your dates in ISO format, which SQL is giving you? The format you want is a protest against the Gregorian calendar, and it is really rather late for that.

by timfox

If SQL's result is known to be a date, then I would have thought...

Public Function ChangeDate (dteOldDate as date) as Date
ChangeDate = format("dd/mm/yyyy")
End Function

...would have worked.

by andrew

try:

declare @d varchar(8)
set @d = '20010504'
select convert(char(10),cast(@d as datetime),101)

This discussion is closed to new replies.