Re: Workdays function with Australian Dates
- From: "Arno R" <arraNOcomSPAM@xxxxxxxxxx>
- Date: Sat, 18 Mar 2006 14:02:13 +0100
Thanks very much Roy for this very clear explanation!
Arno R
"RoyVidar" <roy_vidarNOSPAM@xxxxxxxx> schreef in bericht news:mn.8ac07d633bf0e68f.33955@xxxxxxxxxxx
Arno R wrote in message <4419f65a$0$2021$ba620dc5@xxxxxxxxxxxxxxxxxxx>.
:
"RoyVidar" <roy_vidarNOSPAM@xxxxxxxx> schreef in bericht
news:mn.84fd7d637ddfdab3.33955@xxxxxxxxxxx
Arno R wrote in message <441967ae$0$23339$ba620dc5@xxxxxxxxxxxxxxxxxxx>
So StartDate would become Clng(StartDate) and so on.
Arno, have you tried that number trick on SQL server using ADO?
My guess would be that there would be a difference of a couple of days
when executing something like that on a separate connection to the
server vs on linked tables.
Then, what about upsizing your db to other platforms ...?
--
Roy-Vidar
To be honest I never tried that with ADO.
But I did try that with DAO and ODBC-connections to SQL-server.
Why would ADO make a difference here?
The date-portion of a date-field date is just an integer value isn't it??
Is this not so when using ADO ???
Arno R
I haven't bothered testing much either, but threw this little thinge
together just now.
On my setup, it demonstrates that under some circumstances, there will
be an offset of two days when using "semi magic numbers" for date
manipulations.
Create a small table
create table newDateTest (
id int identity primary key,
myDate datetime,
myText varchar(20))
Then try something like this
Sub testing()
Dim cnL As ADODB.Connection
Dim cnD As ADODB.Connection
Dim rs As ADODB.Recordset
Dim db As DAO.Database
Dim strSQL As String
Set cnL = CurrentProject.Connection
Set db = DBEngine(0)(0)
Set cnD = New ADODB.Connection
cnD.ConnectionString = _
"Provider=sqloledb;" & _
"Data Source=steknobb02\stekno;" & _
"Initial Catalog=msp;" & _
"Integrated Security=SSPI"
cnD.Open
strSQL = "insert into dbo.newDateTest " & _
"(myText, MyDate) Values ('ADO OLE DB number'," & _
CLng(Date) & ")"
cnD.Execute strSQL, , adCmdText + adExecuteNoRecords
strSQL = "insert into dbo_newDateTest " & _
"(myText, MyDate) Values ('ADO ODBC number'," & _
CLng(Date) & ")"
cnL.Execute strSQL, , adCmdText + adExecuteNoRecords
strSQL = "insert into dbo_newDateTest " & _
"(myText, MyDate) Values ('DAO ODBC number'," & _
CLng(Date) & ")"
db.Execute strSQL, dbFailOnError
strSQL = "insert into dbo.newDateTest " & _
"(myText, MyDate) Values ('ADO OLE DB date', '" & _
Format$(Date, "yyyy-mm-dd") & "')"
cnD.Execute strSQL, , adCmdText + adExecuteNoRecords
strSQL = "insert into dbo_newDateTest " & _
"(myText, MyDate) Values ('ADO ODBC date', #" & _
Format$(Date, "yyyy-mm-dd") & "#)"
cnL.Execute strSQL, , adCmdText + adExecuteNoRecords
strSQL = "insert into dbo_newDateTest " & _
"(myText, MyDate) Values ('DAO ODBC date', #" & _
Format$(Date, "yyyy-mm-dd") & "#)"
db.Execute strSQL, dbFailOnError
Debug.Print "Get all"
Set rs = cnL.Execute("select * from dbo_newdatetest", , _
adCmdText)
Debug.Print rs.GetString
Debug.Print "Get records for current date"
Debug.Print "through formatting date to string"
strSQL = "select * from dbo_newDateTest where MyDate = #" & _
Format(Date, "yyyy-mm-dd") & "#"
Set rs = cnL.Execute(strSQL, , adCmdText)
Debug.Print rs.GetString
Debug.Print "Get records for current date"
Debug.Print "through converting date to long"
strSQL = "select * from dbo_newDateTest where MyDate = " & _
CLng(Date)
Set rs = cnL.Execute(strSQL, , adCmdText)
Debug.Print rs.GetString
Set db = Nothing
End Sub
On my setup, this gave the following results
Get all
1 19.03.2006 ADO OLE DB number
2 17.03.2006 ADO ODBC number
3 17.03.2006 DAO ODBC number
4 17.03.2006 ADO OLE DB date
5 17.03.2006 ADO ODBC date
6 17.03.2006 DAO ODBC date
Get records for current date
through formatting date to string
2 17.03.2006 ADO ODBC number
3 17.03.2006 DAO ODBC number
4 17.03.2006 ADO OLE DB date
5 17.03.2006 ADO ODBC date
6 17.03.2006 DAO ODBC date
Get records for current date
through converting date to long
1 19.03.2006 ADO OLE DB number
I would primarly recommend utilizing the parameters collection of the
objects one are using, which will not only easily overcome these date
challenges, but also overcome the challenges with single quotes/special
characters in strings and the hassle of working with numbers with
decimals when your regional settings specify comma as decimal
separator.
Oh - not to forget, using parameters also prevents SQL injection
attacks.
When using dynamic SQL - I would support Lyles suggestion of formatting
to string, and use an unambiguous format. yyyy-mm-dd (ISO 8601) or
"escaped US version" mm\/dd\/yyyy.
--
Roy-Vidar
- References:
- Workdays function with Australian Dates
- From: Dixie
- Re: Workdays function with Australian Dates
- From: Jeff
- Re: Workdays function with Australian Dates
- From: Dixie
- Re: Workdays function with Australian Dates
- From: Arno R
- Re: Workdays function with Australian Dates
- From: RoyVidar
- Re: Workdays function with Australian Dates
- From: Arno R
- Re: Workdays function with Australian Dates
- From: RoyVidar
- Workdays function with Australian Dates
- Prev by Date: Re: help with search - using query
- Next by Date: Re: Keywords in bibliography database
- Previous by thread: Re: Workdays function with Australian Dates
- Next by thread: Update query exception based on parameter
- Index(es):
Relevant Pages
|