|
-
Jul 20th, 2006, 03:51 AM
#1
Thread Starter
Frenzied Member
How to manipulate a string field in a SQL statement ?
I am grabbing a field from a table that is defined as a string. It is actually a date in the format YYYYMMDD.
What I would like to do is put something in the SQL statement so that when it comes back it reads as "DD/MM/YYYY".
Is this easy enuff to do ?
Last edited by TheBionicOrange; Jul 20th, 2006 at 04:18 AM.
-
Jul 20th, 2006, 04:17 AM
#2
Thread Starter
Frenzied Member
Re: How to manipulate a string field in a SQL statement ?
OK found it.
I used :
VB Code:
SELECT SUBSTRING(Audit_Date, 7, 2) + '/' + SUBSTRING(Audit_Date, 5, 2) + '/' + SUBSTRING(Audit_Date, 1, 4) AS Expr1
FROM Audit_Location_Summary
-
Jul 20th, 2006, 01:44 PM
#3
Re: How to manipulate a string field in a SQL statement ?
You could just format the date field value once you get it:
MyStr = Format(MyRS.Fields("Audit_Date").Value,"dd/mm/yyyy")
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jul 21st, 2006, 02:40 AM
#4
Thread Starter
Frenzied Member
Re: How to manipulate a string field in a SQL statement ?
No I couldn't, well not in this case. The recordset is being thrown straight at a grid. Thats why I needed to get it sorted within the SQl.
-
Jul 21st, 2006, 11:27 AM
#5
Re: How to manipulate a string field in a SQL statement ?
Then format the grid column.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jul 21st, 2006, 11:40 AM
#6
Re: How to manipulate a string field in a SQL statement ?
As long as you are using a "proper" database (like SQL Server, as I think TheBionicOrange is) it's much more efficient to do it in the SQL.
-
Jul 21st, 2006, 11:41 AM
#7
Re: How to manipulate a string field in a SQL statement ?
if you are using SQL Server then its a lot simpler. You can just construct your sql statement to convert your string into a date 
Code:
select convert(varchar(10), convert(datetime, YourStringDateField), 103) from YourTable.....
the general syntax is
convert(datatype, FieldToConvert, FormatOptions)
In our case formatOption 103 will give you string in a date-like format dd/mm/yyyy
-
Jul 21st, 2006, 12:13 PM
#8
-
Jul 21st, 2006, 12:30 PM
#9
Re: How to manipulate a string field in a SQL statement ?
 Originally Posted by si_the_geek
 I've just seen a ghost!!
Welcome back Serge! 
A ghost for sore eyes!
I had to double check the date time stamp on the post. I thought for a moment someone had posted in the very old thread. Nice to see a Serge post again. Hopefully, the time between this one and the last one won't be as long.
-
Jul 24th, 2006, 02:41 AM
#10
Thread Starter
Frenzied Member
Re: How to manipulate a string field in a SQL statement ?
Thanks for that Serge .. I'll make a note of that one.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|