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 1,860 other subscribers

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's avatar

    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's avatar

      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's avatar

    Lachlan Gemmell said

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

    • jpluimers's avatar

      jpluimers said

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

      • evdkraan's avatar

        evdkraan said

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

        use parameters instead of literals

        –Edwin

      • Lachlan Gemmell's avatar

        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's avatar

          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's avatar

        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 to François Cancel reply

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