Re: ADP ignoring my format code

From: Brendan Reynolds (brenreyn)
Date: 09/27/04


Date: Mon, 27 Sep 2004 11:56:46 +0100

Hi Vadim,

Sorry about the delay in replying, I was ill for a few days last week.

If the month is all that is required, and MyDate is a Date variable, and
we're talking VBA, not SQL, then all we need is Month(MyDate).

As I remember it though, what the original poster wanted was a string
representation of a complete date in US format. That would work with Jet
SQL, which, in 32-bit versions, expects dates in that format, regardless of
the current locale.

The question I was attempting to address was the question posed in the
subject line, why was the formatting code not producing the expected result?
But there is I think another question here, which is whether this Jet SQL
technique is appropriate in an ADP/SQL Server context?

I'm not any kind of expert on SQL Server, but I see that the SQL Server
Books Online topic, "Writing International Transact-SQL Statements" lists
three solutions to this problem - use the ODBC timestamp, date, and time
escape clauses, use the unseperated numeric strings (yyyymmdd, which if I
remember correctly is what Lyle suggested) or use the CONVERT statement with
an explicit style parameter.

-- 
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com
The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
"Vadim Rapp" <vrapp@nospam.polyscience.com> wrote in message 
news:%23aZNhJAoEHA.1052@TK2MSFTNGP10.phx.gbl...
> Hello Brendan:
> You wrote  on Tue, 21 Sep 2004 11:42:27 +0100:
>
> BR> Better still, use the Format$ version of the function, which returns a
> BR> String, rather than a Variant of sub-type String, avoiding the
> BR> unnecessary implicit conversion from Variant to String).
>
> I think the proper way to address this problem is using functions like
> DatePart.
>
> I.e. for example, if I want to extract the month from the date, the bad 
> code
> will be
>
> Month = mid(MyDate,1,2)
>
> The good code will be
>
> Month = datepart("m",MyDate)
>
> This is good practice even for domestic-only applciations; for the
> international ones, it's absolutely mandatory.
>
> Actually, the whole Y2K issue was because people were using (1) instead of
> (2).
>
>
> Vadim
> ----------------------------------------
> Vadim Rapp Consulting
> SQL, Access, VB Solutions
> 847-685-9073
> www.vadimrapp.com
> 


Relevant Pages

  • Re: Moving a VBA function to SQL server
    ... SQL is a set-based language. ... "String Functions " in Books Online. ... This will produce a job header formatted like this: ... The format he specifies is stored in table 'Settings' - field 'JobHdrMask' ...
    (comp.databases.ms-access)
  • Re: Storing Doubles in SQL
    ... Also it's pointless to format the value before storing it. ... Dave Patrick ....Please no email replies - reply in newsgroup. ... string and format as in: ... >I can successfully read and write from/to sql using excel macros. ...
    (microsoft.public.excel.programming)
  • Re: Searching on DATETIME Fields
    ... So First try quoting the string, then ensure that the format of the date ... Wayne Snyder, MCDBA, SQL Server MVP ... >>> The field I am querying is of DATETIME data type, ...
    (microsoft.public.sqlserver.server)
  • Re: simple query not so simple
    ... If that is truly your SQL statement, you have just asked to find all ... In Oracle all dates contain 'century, year, month, date, hour, minute, ... string - if you can read it, it's a string, not a date - so use string ... either implicitly (if your string is in the session's date format) ...
    (comp.databases.oracle.misc)
  • Re: Problems with Delete Command
    ... The SQL could get fairly messy if you need to construct it in code, ... ContactID, and WebComID, and create your on-the-fly SQL on that saved query, ... to find the list of ContactIDs from the junction table, ... This is a style/readability thing: if you are going to use string ...
    (microsoft.public.access.tablesdbdesign)