Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / January 2008

Tip: Looking for answers? Try searching our database.

"Convert" command?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ricardo Vazquez - 11 Jan 2008 11:05 GMT
Hi everybody!

Is there a SQL command for MS Access similar to the CONVERT command in
Transact-SQL?
And could you please help me an usage example?

I need to change a DateTime format, something like this:

(this is what I would do in SQLServer):

SELECT distinct(CONVERT(char(11),dateField,105))
from Table1
order by CONVERT(char(11),dateField,105)

Thank you!

Ricardo.
Stefan Hoffmann - 11 Jan 2008 11:19 GMT
hi Ricardo,

> Is there a SQL command for MS Access similar to the CONVERT command in
> Transact-SQL?
Not SQL, but VBA. Take a look at CDate(), CStr(), CLng, etc in the OH.

mfG
--> stefan <--
Michel Walsh - 11 Jan 2008 15:04 GMT
You need to relay on VBA functions, which can be called directly from within
the JET SQL statement (and if you are within MS ACCESS), without having to
register anything (unlike using C#/Vb.Net with MS SQL Server). You can use
CDate( ), but that highly depends on the PC Setting the query runs onto, to,
silently, prefers dd-mm-yyyy over mm-dd-yyyy. It is even worse, since you
don't really control which PC will ever run your query, if the string uses
local month name, since, say, on some PC, the three letters month's name, if
not in English, the month name may not be understood at all. You can use
MID(string, start, lengthOfSubstring)  to 'slice' the original string. As
example, DateSerial( ) is a VBA function which accepts three arguments: the
year, the month and the day (all integers). So, someone can use:

   DateSerial(  INT(MID( myString, 7, 4)),  INT(MID(myString, 4, 2)),
INT(LEFT(myString, 2))  )

Note that the three INT()  are not really required, since VBA would
automatically convert the three substrings to the intended integers, but it
does not hurt explicitly forcing the conversion ourselves.
(I assumed your string was like "dd-mm-yyyy" ).

Vanderghast, Access MVP

> Hi everybody!
>
[quoted text clipped - 13 lines]
>
> Ricardo.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.