The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,810 other followers

Date Time SQL Queries: Formatting Date Time Values for Access SQL in Delphi

Posted by jpluimers on 2010/07/08

Five words:

use parameters instead of literals.

via: Date Time SQL Queries: Formatting Date Time Values for Access SQL in Delphi.

Edit: Fixed “in stead of” into “instead of”: learned something new today :-)

–jeroen

9 Responses to “Date Time SQL Queries: Formatting Date Time Values for Access SQL in Delphi”

  1. shmia said


    function DateTimeForSQL(const dateTime : TDateTime) : string;
    begin
    result := FormatDateTime('#yyyy-mm-dd hh.nn.ss#', dateTime) ;
    end

    This code could replaced by

    function DateTimeForSQL(const dateTime : TDateTime) : string;
    begin
    // MS Access accepts a floating point value as datetime data type
    // Luckily Delpi's TDateTime is nothing other than Access' date time
    result := FloatToStr(dateTime);
    ReplaceChar(Result, DecimalSeparator,'.');
    end

    • jpluimers said

      I’m not sure that will always work; mixes of Acces MDB files on a server with a different locale than the clients (and maybe even different locales on several clients).

      Parameters will always work.

      –jeroen

  2. Lachlan Gemmell said

    Good advice though I’d normally say it in 5 words instead of 6 ;-)

    • jpluimers said

      Oh – this always bites me as a non-native English speaker; are “in stead of” and “instead of” both valid?
      –jeroen

      • evdkraan said

        No, only ‘instead of’ is valid, so it should be five words:

        use parameters instead of literals

        –Edwin

      • Lachlan Gemmell said

        I can’t say for certain that “in stead” is incorrect, it must be where the word “instead” comes from. A native english speaker would almost certainly use the word “instead” in that context though. Thanks for being such a good sport, my apologies for poking a little fun at your English (which usually pretty close to perfect by the way).

        • jpluimers said

          I’m glad you poked at me; it made me learn something new, which is one of the things I like in life most :-)

          Thanks for the compliments!

          –jeroen

      • François said

        The confusion is probably because of the similar expression “in one’s stead”:

        http://en.wiktionary.org/wiki/in_one's_stead
        http://en.wiktionary.org/wiki/instead

        So, in your stead, I would have written “instead”. :-)

        And for the content, I agree 200% with you. parameters, parameters, parameters!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: