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
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
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!
jpluimers said
Splendid; I love languages :-)
–jeroen