Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simultaneous trim and format in Access SQL? 1

Status
Not open for further replies.

merlynsdad

Programmer
Nov 18, 2010
175
US
I have a WHERE statement with a string of numbers representing a date, e.g. 1110708 = 7/8/2011. I need to trim the left digit, then format it as DDMMYY, preferably in the same WHERE statement. Can I trim and format simultaneously in Access SQL, and if so, how?

If the square peg won't fit in the round hole, sand off the corners.
 
Actually, what I need to do is to convert the number in the WHERE statement in the Date field of SELECT, rather than in the WHERE statement. Sorry about that.

If the square peg won't fit in the round hole, sand off the corners.
 

So, what do you have now (as a SELECT statement) and what would you like to have? An example goes a long way.

Have fun.

---- Andy
 



Hmmmmm???

You posted 1110708

Breaking it apart visually...
[tt]
111 07 08
[/tt]
What is the [red]111[/red] supposed to be?


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I have no idea what the leading 1 is for, but the 1's in the 2nd and 3rd positions represent 2011. I'm trimming that leftmost 1 before I start. What I have now is:

SELECT right(trim(atlanta_agent.uday),6) AS [Date]

The "uday" is the 1110708. The [Date] field will currently show me 110708 if it's a text field, but I'd prefer it as date/time.

If the square peg won't fit in the round hole, sand off the corners.
 
SELECT DateSerial(1900+Left(atlanta_agent.uday,2),0+Mid(atlanta_agent.uday,4,2),0+Right(atlanta_agent.uday,2)) AS [Date]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top