General discussion

Locked

SQL Result Set Formatting

By vhansen86 ·
I have a SQL Result Set I want to format. It is a date being returned as 20010504 it is varchar(. I want the result to look like 05/04/2001.

This conversation is currently closed to new comments.

11 total posts (Page 1 of 2)   01 | 02   Next
| Thread display: Collapse - | Expand +

All Comments

Collapse -

SQL Result Set Formatting

by MedievalDude In reply to SQL Result Set Formatting

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.

Collapse -

SQL Result Set Formatting

by vhansen86 In reply to SQL Result Set Formatting

Poster rated this answer

Collapse -

SQL Result Set Formatting

by john_wills In reply to SQL Result Set Formatting

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.

Collapse -

SQL Result Set Formatting

by vhansen86 In reply to SQL Result Set Formatting

I provide what I am asked to provide.

Collapse -

SQL Result Set Formatting

by john_wills In reply to SQL Result Set Formatting

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.

Collapse -

SQL Result Set Formatting

by vhansen86 In reply to SQL Result Set Formatting

I provide what I am asked to provide.

Collapse -

SQL Result Set Formatting

by timfox In reply to SQL Result Set Formatting

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.

Collapse -

SQL Result Set Formatting

by vhansen86 In reply to SQL Result Set Formatting

Poster rated this answer

Collapse -

SQL Result Set Formatting

by andrew In reply to SQL Result Set Formatting

try:

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

Collapse -

SQL Result Set Formatting

by vhansen86 In reply to SQL Result Set Formatting

Thank you!

Back to Web Development Forum
11 total posts (Page 1 of 2)   01 | 02   Next

Related Discussions

Related Forums