[Gambas-user] Using dates in Gambas

David Silverwood the_watchmann at yahoo.com
Tue May 21 20:50:21 CEST 2019


 Hi Benoit
It will be great if you can explain the database date handling because I can for the life of me not get Gambas to keep a sqlite date in sqlite format. (when loading from the database). Tried Str$, Format$, etc and no luck to date. It defaults to US format no matter what I try. I thought it had to do with my regional settings but Gambas apparently reads that perfectly when using 
Print System.TimeZonePrint System.Language
 last try Gambas complained as follows: 

The following error has occurred:
Type mismatch: wanted Date, got String instead (PS. I wanted a "date" as a string and not a date, in the hope that gambas would leave it alone...)
I'm about ready to give up here...
Many thanks
David

    On Saturday, May 18, 2019, 1:54:08 PM GMT+2, Gianluigi <bagonergi at gmail.com> wrote:  
 
 

Il giorno ven 17 mag 2019 alle ore 21:44 Benoît Minisini <g4mba5 at gmail.com> ha scritto:

Hi,

As I notice that almost nobody suceeds in dealing with date & time 
correctly, I started to wrote a overview about that in the wiki.

http://gambaswiki.org/wiki/doc/date

Please feal free to comment and modify this page so that date & time 
management becomes as clear as possible.

This is still a work in progress, and I especially need "how to" code 
example about dates.

Regards,

-- 
Benoît Minisini



Hi Benoit,
probably could have inspired what I wrote here:

https://lists.gambas-basic.org/pipermail/user/2019-May/067200.html

In fact when I write:

"Left(Str(hDate), 10) '(international)"

I don't mean UTC but I mean "displaying the date in local format in all countries"
And when I write:

"Format(hDate, "dd/mm/yyyy") '(Local)"

I mean "displaying the date in local format only in your country"

In my defense, I have attached a project that contains this code that better explains what I wanted to say:
-------------------------------------------
' From a Sotema code
Public Sub Main()

  Dim hConn As Connection
  Dim hResult As Result
  Dim hTable As Table
  ' Activate the display of gb.db messages
  db.Debug = True
  ' Set the connection parameters
  With hConn = New Connection
    .Type = "sqlite"
    .Host = System.User.Home
    .Open
  End With
  ' if the db exists, delete it.
  ' this allows you to run the example several times
  If (hConn.Databases.Exist("exampledb")) Then
    hConn.Databases.Remove("exampledb")
    hConn.Databases.Add("exampledb")
  Endif
  hConn.Name = "exampledb"
  ' create the table
  hTable = hConn.Tables.Add("users")
  hTable.Fields.Add("id", db.Integer)
  hTable.Fields.Add("name", db.String, 80)
  hTable.Fields.Add("birth", db.Date)
  
  hTable.Update()
  ' add one record
  hConn.Begin()
  hResult = hConn.Create("users")
  hResult!id = 1
  hResult!name = "Gianluigi"
  hResult!birth = Date(1947, 4, 10)
  hResult.Update()
  hConn.Commit()
  ' retrieve the record
  hResult = hConn.Find("users") ' the same as  select * from users
  ' hResult = hConn.Exec("SELECT * FROM users")
  Print Left(Str(hResult["birth"]), 10)
  'Print Format(hResult["birth"], "dd/mm/yyyy")

End
------------------------------------------

and I had previously referred to ReportTest on the Software farm, that treats dates the same way.

Regards
Gianluigi 

----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190521/dca16016/attachment-0001.html>


More information about the User mailing list