Date issue

This forum is meant for questions and discussions about the X# language and tools
Post Reply
stecosta66
Posts: 96
Joined: Mon Sep 26, 2016 12:59 pm
Location: Italy

Date issue

Post by stecosta66 »

Hi All

using X# 2.21 and XS2ADO 5.0.6 to connect to a Postgres 17 Database

I've a tight loop used to populate a bArrayServer from an AdoRecordset and I'm facing a little issue with date fields.

When a date is retrieved, FieldType is 133 which is an AdoDataTypeEnum, as per xs2ado documentation, is "adDBDate 133 - A date value (yyyymmdd) (DBTYPE_DBDATE)."

Instead I get a date from System.DateTime that has a format of "dd/mm/yyyy 00:00:00" so it cannot be stored in the field of bArrayServer defined as type "D" (I get a blank field).

AdoSetTimeAsDate is set to TRUE.

Image

the code looks like this:

Code: Select all

				LOCAL odbInvoicePayments AS AdoRecordset
				
				[...]
				
				SELF:oasInvoicePayments:Append()
				FOR y := 1 UPTO dwFields
					cFieldName := Lower( odbInvoicePayments:Fields:Item[ y ]:Name )	// for debugging purpose
					uFieldType := odbInvoicePayments:Fields:Item[ y ]:Type 		// for debugging purpose
					uValue := odbInvoicePayments:FIELDGET( y ) 
					SELF:oasInvoicePayments:FIELDPUT( y, uValue )
				NEXT
				SELF:oasInvoicePayments:Commit()
				
				[...]
How workaround this?

Thanks
Stefano
stecosta66
Posts: 96
Joined: Mon Sep 26, 2016 12:59 pm
Location: Italy

Re: Date issue

Post by stecosta66 »

HI All,

following my own reply I've done some little adjustment to my code.

Added a LOCAL dDateValue AS DATE so conversion from System.DateTime is automatic

Code: Select all


	SELF:oasInvoicePayments:Append()
	FOR y := 1 UPTO dwFields
		cFName := Lower( odbInvoicePayments:Fields:Item[ y ]:Name )
		uFieldType := odbInvoicePayments:Fields:Item[ y ]:Type 
                    
		IF uFieldType == adDBDate
			dDateValue := odbInvoicePayments:FIELDGET( y ) 
			SELF:oasInvoicePayments:FIELDPUT( y, dDateValue )
                        
		ELSE
			uValue := odbInvoicePayments:FIELDGET( y ) 
			SELF:oasInvoicePayments:FIELDPUT( y, uValue )

		ENDIF
	NEXT
Issue persist instead on an AdoServer directly attached to a bBrowser that display date column as "dd/mm/yyyy 00:00:00".
In this case NO conversion is made on date field. There is any advice to avoid this?

Thanks
Stefano
User avatar
ArneOrtlinghaus
Posts: 416
Joined: Tue Nov 10, 2015 7:48 am
Location: Italy

Re: Date issue

Post by ArneOrtlinghaus »

We use Oracle which should be very similar to PostGres and we make some initialization settings when connecting to the database to be independent of user settings. Below I have put all commands although only two should be important for you.
alter session set NLS_TERRITORY = GERMANY
alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS'
alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SSXFF'
alter session set nls_language = english
ALTER SESSION set NLS_NUMERIC_CHARACTERS = ".,"
alter session set nls_sort = BINARY
ALTER SESSION SET recyclebin = OFF
alter session set ddl_lock_timeout = 600
alter session set session_cached_cursors=1000

Arne
User avatar
robert
Posts: 4574
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Date issue

Post by robert »

Stefano,
If you add a call to AdoDateTimeAsDate(TRUE) then DateTime values should be returned as Date.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
stecosta66
Posts: 96
Joined: Mon Sep 26, 2016 12:59 pm
Location: Italy

Re: Date issue

Post by stecosta66 »

Hi Robert,

I have AdoDateTimeAsDate(TRUE) at the start of my app. This works fine in VO + bBrowser + Vo2Ado but not in X#.
As described above when I attacch an AdoServer (Xs2Ado) directly to a bBrowser (X# edition) the date column show 'dd/mm/yyyy 00:00:00'.

VO + Vo2Ado + bBrowser
Image

X# + Xs2Ado + bBrowser (X# edition)
Image

same settings, same code

using X# 2.21 + Xs2Ado 5.0.6 + bBrowser X# edition 4.4.34

in both versions I'm connecting against a Postgres 17 database

Thanks
Stefano
Post Reply