Re: Sql mdb
- From: "Paul Scott" <paul.scott@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 13 Feb 2008 10:04:57 -0000
On Wed, 13 Feb 2008 06:32:06 -0000, limelect <limelect@xxxxxxxxxxxx> wrote:
As for date (my last quest) is the date field (time) a string??
Becouse i used it as a date format
i wander if...
Do you know of a function to convert date/time to mdb format?
SQL := 'Select * from table where startdate = #11-09-2008#';
If you use that date format you will come to grief when you run your program on a PC in a different country (did you mean 11'th September or 9'th November?) - or on a PC with different date/time separators or formats.
Better to use the ISO formats "YYYY-MM-DD" which are unambiguously understood by both SQLserver and MSAccess (and other DBs?)
SQLServer: 'yyyy-mm-dd hh:nn:ss'
MS Access: #yyyy-mm-dd hh:nn:ss#
(Why, oh why, oh why, do these two MS databases *still* have different date formats?)
Cobbled together from various units just to give you the general idea - but I've not even tried to compile it!
const cIsoString_DateSeparator = '-' ;
const cIsoString_ClockSeparator = ':' ;
function TimeToIsoString ( const aTime : tTimeX ) : tIsoString ;
begin
result := FormatDateTime ( aTime, 'yyyy-mm-dd hh:nn:ss' ) ;
// Because the DateSeparator is "/", our dashes "-" will be copied to the output
// but ":" denotes the "TimeSeparator", so FormatDateTime will replace it with
// this PC's "TimeSeparator" - so we need to check if it has been altered from ":"
if ( TimeSeparator <> cIsoString_ClockSeparator ) then begin
result := AnsiReplaceText ( result, TimeSeparator, cIsoString_ClockSeparator ) ;
end ;
end ; // TimeToIsoString
function TimeToDatabaseString
( const aTime : tTimeX ;
const aDatabaseEngine : tDatabaseEngine )
: tStringX ;
var
DateDelimiter : tCharX ;
begin
DateDelimiter := SqlDateDelimiter [aDatabaseEngine] ; // Access "#", SQLServer "'"
result := DateDelimiter + TimeToIsoString (aTime) + DateDelimiter ;
end ; // TimeToDatabaseString
tDatabaseEngine = "MSJet", "MSSqlServer"
tIsoString = tStringX = "string"
tTimeX = "tDateTime" ;
--
Paul Scott
Information Management Systems
Macclesfield, UK.
.
- Follow-Ups:
- Re: Sql mdb
- From: Vitali Kalinin
- Re: Sql mdb
- References:
- Sql mdb
- From: limelect
- Re: Sql mdb
- From: MikeR
- Re: Sql mdb
- From: limelect
- Sql mdb
- Prev by Date: Re: Sql mdb
- Next by Date: Re: Sql mdb
- Previous by thread: Re: Sql mdb
- Next by thread: Re: Sql mdb
- Index(es):
Relevant Pages
|