niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » IBM DB2
ADO dates and '0001-01-01'
Post new topic   Reply to topic Page 1 of 1 [8 Posts] View previous topic :: View next topic
Author Message
smcgouga@yahoo.com
*nix forums beginner


Joined: 15 Mar 2005
Posts: 2

PostPosted: Tue Mar 15, 2005 10:21 am    Post subject: ADO dates and '0001-01-01' Reply with quote

Visual Basic 6. ADO 2.8

I have an as400 DB2 V5R1 datasource. Dates are defined as *ISO format
and have a range from '0001-01-01' to '9999-12-31'. I am trying to
update a date field on the database with a value of '0001-01-01'
(*LOVAL) The problem is that I need to use ADO cursors and can not
use the SQL update command:
"update tbl set dateField = '0001-01-01 where ..." (note this works no
problem)

The problem stems from the limitation on PC dates. the lowest value a
PC date can have is '0100-01-01'. When ADO reads a value of
'0001-01-01' it fills an ADO recordset with "00:00:00". I can deal
with this by formatting on screen.

However I am not able to set an ADO field to '0001-01-01' since it is
not a valid PC date. How can I set a date field back to '0001-01-01'
using updateBatch or update via ADO?

Ive tried saving the ADO RS to XML to fiddle the schema to change the
date field to a character field so that it would accept "0001-01-01".
This works and fools the recordset but will not update the database on
an update/updatebatch!

Could there be a workaround using triggers or a translation DLL? It
would be much better if I could keep the solution within my VB code.

Cheers
Stu

Option Explicit

Dim CN As New ADODB.Connection
Dim RS As New ADODB.Recordset

Private Sub Command1_Click()
Dim sSQL As String
sSQL = "select prikey, anyDate from tbl where prikey = 1"

RS.Open sSQL, CN, adOpenStatic, adLockBatchOptimistic, adCmdText

Debug.Print RS.Fields("anyDate").Value
'"2005-03-13"

RS.Fields("anyDate").Value = dateserial(1,1,1)
Debug.Print RS.Fields("anyDate").Value
'"0100-01-01" 'close: only 100 years out!

RS.Fields("anyDate").Value = 0
Debug.Print RS.Fields("anyDate").Value
'"00:00:00" 'looks promising but updates DB with '1899-12-31

RS.updatebatch

End Sub

Private Sub Form_Load()
Set CN = New ADODB.Connection

CN.CursorLocation = adUseClient
CN.Open "Driver={Client Access ODBC Driver (32-bit)};" & _
"System=**SYSTEM_NAME**;" & _
"DBQ=**CATALOG_NAME**;" & _
"Uid=**USERNAME**;" & _
"Pwd=**PASSWORD**;" & _
"Commpression = 1;" & _
"Signon = 2;" & _
"Blocksize=512;" & _
"Prefetch=1;"
End Sub
Back to top
Rhino
*nix forums Guru


Joined: 08 Feb 2005
Posts: 449

PostPosted: Tue Mar 15, 2005 1:22 pm    Post subject: Re: ADO dates and '0001-01-01' Reply with quote

<smcgouga@yahoo.com> wrote in message
news:40e5ab91.0503150321.4d10d38c@posting.google.com...
Quote:
Visual Basic 6. ADO 2.8

I have an as400 DB2 V5R1 datasource. Dates are defined as *ISO format
and have a range from '0001-01-01' to '9999-12-31'. I am trying to
update a date field on the database with a value of '0001-01-01'
(*LOVAL) The problem is that I need to use ADO cursors and can not
use the SQL update command:
"update tbl set dateField = '0001-01-01 where ..." (note this works no
problem)

The problem stems from the limitation on PC dates. the lowest value a
PC date can have is '0100-01-01'. When ADO reads a value of
'0001-01-01' it fills an ADO recordset with "00:00:00". I can deal
with this by formatting on screen.

However I am not able to set an ADO field to '0001-01-01' since it is
not a valid PC date. How can I set a date field back to '0001-01-01'
using updateBatch or update via ADO?

Ive tried saving the ADO RS to XML to fiddle the schema to change the
date field to a character field so that it would accept "0001-01-01".
This works and fools the recordset but will not update the database on
an update/updatebatch!

Could there be a workaround using triggers or a translation DLL? It
would be much better if I could keep the solution within my VB code.

Cheers
Stu

Option Explicit

Dim CN As New ADODB.Connection
Dim RS As New ADODB.Recordset

Private Sub Command1_Click()
Dim sSQL As String
sSQL = "select prikey, anyDate from tbl where prikey = 1"

RS.Open sSQL, CN, adOpenStatic, adLockBatchOptimistic, adCmdText

Debug.Print RS.Fields("anyDate").Value
'"2005-03-13"

RS.Fields("anyDate").Value = dateserial(1,1,1)
Debug.Print RS.Fields("anyDate").Value
'"0100-01-01" 'close: only 100 years out!

RS.Fields("anyDate").Value = 0
Debug.Print RS.Fields("anyDate").Value
'"00:00:00" 'looks promising but updates DB with '1899-12-31

RS.updatebatch

End Sub

Private Sub Form_Load()
Set CN = New ADODB.Connection

CN.CursorLocation = adUseClient
CN.Open "Driver={Client Access ODBC Driver (32-bit)};" & _
"System=**SYSTEM_NAME**;" & _
"DBQ=**CATALOG_NAME**;" & _
"Uid=**USERNAME**;" & _
"Pwd=**PASSWORD**;" & _
"Commpression = 1;" & _
"Signon = 2;" & _
"Blocksize=512;" & _
"Prefetch=1;"
End Sub

I don't know anything about ADO and I know darn little about AS/400 for that
matter. However it sounds to me like you might be better off to store null
rather than 0001-01-01 in your date fields.

Personally, I would only ever want to see 0001-01-01 in a date field if it
was the date that some specific thing actually happened but you seem to be
using it as a placeholder, not to represent a real date. Therefore, it would
make more sense to me to store a null, which means "unknown or not
applicable".

I don't know if ADO recognizes the concept of nulls so I don't know if it
has syntax to let you change a value to null but you might want to
investigate this if my argument has persuaded you.

Rhino
Back to top
smcgouga@yahoo.com
*nix forums beginner


Joined: 15 Mar 2005
Posts: 2

PostPosted: Wed Mar 16, 2005 10:22 am    Post subject: Re: ADO dates and '0001-01-01' Reply with quote

Quote:
Personally, I would only ever want to see 0001-01-01 in a date field if it
was the date that some specific thing actually happened but you seem to be
using it as a placeholder, not to represent a real date. Therefore, it would
make more sense to me to store a null, which means "unknown or not
applicable".

The database field has been defined as not null and other programs are
expecting the '0001-01-01' value. However I agree that using nulls
may have been the "right" way to do it but too many programs depend on
the value '0001-01-01' now.

Quote:
I don't know if ADO recognizes the concept of nulls so I don't know if it
has syntax to let you change a value to null but you might want to
investigate this if my argument has persuaded you.

Yes ADO will let you use nulls if the field in the database allows
nulls. You can even trick ADO and force nulls (save to xml, edit
recordset definition, open) but the update will cause an error since
the database field still will not allow nulls.

Cheers
Stu
Back to top
Mark Yudkin
*nix forums Guru Wannabe


Joined: 29 May 2005
Posts: 117

PostPosted: Thu Mar 17, 2005 6:06 am    Post subject: Re: ADO dates and '0001-01-01' Reply with quote

VB6 defines that a date string with a two digit year be windowed to the
1930 - 2029 century. The purpose was to ease Y2K migration, the disadvantage
is that you can't enter dates prior to year 100 - not that these commonly
occur in typical data processing tasks (unless you're an archeologist or a
paleontologist, who has data going back that far?). This is VB6 trying to be
helpful with the 2 digit dates so popularly used prior to the late 1990s,
not a limitation on PC dates, and is clearly documented.

Use the DB2 DATE function to effect the conversion from string to DB2 DATE
in SQL. Another possibility is to use the base Windows APIs to effect
conversion, but this is definitely a lot more work, and will hinder any
subsequent port to VB.NET, which gratuitously changed the internal
representation of dates (to maximize Microsoft's earnings in the consultancy
services?)

<smcgouga@yahoo.com> wrote in message
news:40e5ab91.0503150321.4d10d38c@posting.google.com...
Quote:
Visual Basic 6. ADO 2.8

I have an as400 DB2 V5R1 datasource. Dates are defined as *ISO format
and have a range from '0001-01-01' to '9999-12-31'. I am trying to
update a date field on the database with a value of '0001-01-01'
(*LOVAL) The problem is that I need to use ADO cursors and can not
use the SQL update command:
"update tbl set dateField = '0001-01-01 where ..." (note this works no
problem)

The problem stems from the limitation on PC dates. the lowest value a
PC date can have is '0100-01-01'. When ADO reads a value of
'0001-01-01' it fills an ADO recordset with "00:00:00". I can deal
with this by formatting on screen.

However I am not able to set an ADO field to '0001-01-01' since it is
not a valid PC date. How can I set a date field back to '0001-01-01'
using updateBatch or update via ADO?

Ive tried saving the ADO RS to XML to fiddle the schema to change the
date field to a character field so that it would accept "0001-01-01".
This works and fools the recordset but will not update the database on
an update/updatebatch!

Could there be a workaround using triggers or a translation DLL? It
would be much better if I could keep the solution within my VB code.

Cheers
Stu

Option Explicit

Dim CN As New ADODB.Connection
Dim RS As New ADODB.Recordset

Private Sub Command1_Click()
Dim sSQL As String
sSQL = "select prikey, anyDate from tbl where prikey = 1"

RS.Open sSQL, CN, adOpenStatic, adLockBatchOptimistic, adCmdText

Debug.Print RS.Fields("anyDate").Value
'"2005-03-13"

RS.Fields("anyDate").Value = dateserial(1,1,1)
Debug.Print RS.Fields("anyDate").Value
'"0100-01-01" 'close: only 100 years out!

RS.Fields("anyDate").Value = 0
Debug.Print RS.Fields("anyDate").Value
'"00:00:00" 'looks promising but updates DB with '1899-12-31

RS.updatebatch

End Sub

Private Sub Form_Load()
Set CN = New ADODB.Connection

CN.CursorLocation = adUseClient
CN.Open "Driver={Client Access ODBC Driver (32-bit)};" & _
"System=**SYSTEM_NAME**;" & _
"DBQ=**CATALOG_NAME**;" & _
"Uid=**USERNAME**;" & _
"Pwd=**PASSWORD**;" & _
"Commpression = 1;" & _
"Signon = 2;" & _
"Blocksize=512;" & _
"Prefetch=1;"
End Sub
Back to top
Jonathan Bailey
*nix forums beginner


Joined: 17 Mar 2005
Posts: 2

PostPosted: Thu Mar 17, 2005 8:39 am    Post subject: Re: ADO dates and '0001-01-01' Reply with quote

I suppose you could choose to update the lovalue fields in ADO by
setting them to another value - lets say '1899-12-31' then add a
change/add trigger on the as400 file to change any of these dates to
lovalue.

Jonathan
Back to top
Madcap
*nix forums beginner


Joined: 17 Mar 2005
Posts: 1

PostPosted: Thu Mar 17, 2005 5:08 pm    Post subject: Re: ADO dates and '0001-01-01' Reply with quote

Can you make the field's default value "0001-01-01" and then pass it a
NULL value from VB? Sorry if this is off base, my DB experience is
mainly in MySQL.
Back to top
cwahlmeier@data-tronics.c
*nix forums beginner


Joined: 14 Jun 2005
Posts: 11

PostPosted: Thu Mar 24, 2005 10:48 pm    Post subject: Re: ADO dates and '0001-01-01' Reply with quote

Stu,

Date, Time and Timestamps are the such a pain in ADO. I would suggest
using a command object, but you say you cannot use one.
Next I would suggest that you select the date using a CHAR(anyDate). I
see your comment about fooling the recordset but failing the update...
Thus I wonder if the CHAR will meet the same demise.

Also, what is in your DB2CLI.INI file? There are several settings that
affect the interpretation of the date datatype. Many of them are
dependant on the version of your DB2 Client.

Another question, why doesn't the ADODB.Command object work for you?

Regards,

Craig Wahlmeier
Back to top
Bob Barrows [MVP]
*nix forums beginner


Joined: 16 Jul 2006
Posts: 1

PostPosted: Sun Jul 16, 2006 12:26 pm    Post subject: Re: ADO dates and '0001-01-01' Reply with quote

smcgouga@yahoo.com wrote:
Quote:
Visual Basic 6. ADO 2.8

I have an as400 DB2 V5R1 datasource. Dates are defined as *ISO format
and have a range from '0001-01-01' to '9999-12-31'. I am trying to
update a date field on the database with a value of '0001-01-01'
(*LOVAL) The problem is that I need to use ADO cursors and can not
use the SQL update command:
"update tbl set dateField = '0001-01-01 where ..." (note this works no
problem)

The problem stems from the limitation on PC dates. the lowest value a
PC date can have is '0100-01-01'. When ADO reads a value of
'0001-01-01' it fills an ADO recordset with "00:00:00". I can deal
with this by formatting on screen.

However I am not able to set an ADO field to '0001-01-01' since it is
not a valid PC date. How can I set a date field back to '0001-01-01'
using updateBatch or update via ADO?

Ive tried saving the ADO RS to XML to fiddle the schema to change the
date field to a character field so that it would accept "0001-01-01".
This works and fools the recordset but will not update the database on
an update/updatebatch!

Could there be a workaround using triggers or a translation DLL? It
would be much better if I could keep the solution within my VB code.

What is the issue with using a SQL statement? Are you aware that under the

covers, ADO is constructing and executing a sql statement to perform the
update? Why can't you just create the sql statement yourself?

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [8 Posts] View previous topic :: View next topic
The time now is Mon Dec 01, 2008 10:25 pm | All times are GMT
navigation Forum index » Databases » IBM DB2
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts FAQ 4.14 How can I compare two dates and find the differe... PerlFAQ Server Perl 0 Mon Jun 26, 2006 7:03 am
No new posts Need Help comparing dates colincolehour@gmail.com python 12 Fri Jun 16, 2006 12:58 am
No new posts Getting start/end dates given week-number Tim Chase python 3 Fri Jun 09, 2006 2:07 pm
No new posts IF statement regarding dates i love PHP PHP 3 Wed Jun 07, 2006 7:17 pm
No new posts Changing default display format for dates sybase c.lecocq@pixandlog.com Sybase 1 Thu Jun 01, 2006 3:36 pm

Loans | Loans | Loan | Credit Cards UK | Loan Consolidation
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 2.1005s ][ Queries: 16 (0.5562s) ][ GZIP on - Debug on ]