[Gambas-user] DATE function Gambas 3.8.4 (Distro)

David Silverwood the_watchmann at yahoo.com
Thu May 16 17:44:30 CEST 2019


 Oops. typed too quickly... $Date is actually sDate all the way through. Was thinking of another form when I typed this.


    On Thursday, May 16, 2019, 5:38:06 PM GMT+2, David Silverwood via User <user at lists.gambas-basic.org> wrote:  
 
  Dim dDate As DateDim $Date As New String[]

  $Sql = "SELECT * FROM expenses WHERE supplier = '" & cboSupplier.Text & "' AND invoice = '" & edtInvoice.Text & "';"    $Result = conMod.$Con.Exec($Sql)        ' execute sql statement above
  edtRef.Text = $Result!REF  edtDate.Text = $Result!DATE  cboSupplier.Text = $Result!SUPPLIER  edtVatNo.Text = $Result!VAT_NO  edtInvoice.Text = $Result!INVOICE  edtAmount.Text = $Result!AMOUNT  edtVat.Text = $Result!VAT  cboType.Text = $Result!TYPE   edtCash.Text = $Result!CASH  edtChq.Text = $Result!CHEQ  edtCard.Text = $Result!CARD  edtEft.Text = $Result!EFT  edtCr.Text = $Result!CREDIT  edtOs.Text = $Result!OUTSTANDING  edtOrderDate.Text = $Result!ORDER_DATE  edtOrderNo.Text = $Result!ORDER_NO  cboTerms.Text = $Result!TERMS  edtDeliveryDate.Text = $Result!DELIVERY_DATE  edtDeliveryNo.Text = $Result!DELIVERY_RECEIPT  edtSettlement.Text = $Result!SETTLEMENT  edtDueDate.Text = $Result!DUE_DATE  edtChqNo.Text = $Result!CHQ_NO  edtDatePaid1.Text = $Result!DATE_PAID  edtAmtPaid1.Text = $Result!PAID  edtDatePaid2.Text = $Result!ADD_PAYM_DATE  edtAmtPaid2.Text = $Result!ADD_PAYM  edtComments.Text = $Result!COMMENT  cboDescription.Text = $Result!DESCRIPTION    If edtDate.Text Then      edtDate.Text = Left(edtDate.Text, 10)    'for some reason gambas uses mm/dd/yyyy hh:mm     $Date = Split(edtDate.Text, "/")                'split the date into sections to play with the date structure     dDate = Date(sDate[2], sDate[0], sDate[1])        'because gambas switches it around, try and switch it to correct format, eg yyyy mm dd     edtDate.Text = Format$(dDate, "yyyy-mm-dd")   ' converts it back to the proper format... i hope  Endif  I suppose I'm doing this the long way (database and sql coding) but having come from a freebasic/ C and xbasic background this tends to make more sense to me. Never did this in VB6 as sqlite never existed back then.
Thanks for looking into this for me, Charlie.
David
    On Thursday, May 16, 2019, 5:25:07 PM GMT+2, Charlie Ogier <charlie at cogier.com> wrote:  
 
  Hi David,
 
 Can you create and post some code that demonstrates the problem. That will give us something to work with.
 
 Charlie
 
 On 16/05/2019 15:16, David Silverwood via User wrote:
  
 
 Ok, so I'm back with the same problem. It seems to me Gambas has a template format for a date and trying to change it is impossible? As soon as Gambas sees it as a date, it reformats my formatting back to the incorrect format and renders all the code useless. Is this the way it is supposed to be?  
  I need my date formatted to sqlite format, eg, yyyy-mm-dd 
  However, soon as I do that, gambas switches it to mm/dd/yyyy. 
  My OS regional settings are correct. Using Mint 18.3 KDE and Gambas 3.13 (Thanks Charlie for the upgrade tip) 
  The latter format is useless over here and inevitably gambas reads the day and month wrong, by switching it... I've tried using Split and in a debug /print statement I see that it does do exactly what I need, but once the format hits the textbox, Gambas actually changes it back to mm/dd/yyyy. How do I stop that? I tried DIM'ing the dates as Strings but Gambas seems to read dates as dates even if they are dimensioned as strings? (which I know they are 'special' strings of course). 
  My sqlite3 database complains whenever I try and save the dates in Gambas's preferred format. 
  I know I am doing something wrong since no one else has this issue.... but what? 
  
  
      On Tuesday, April 30, 2019, 11:05:06 AM GMT+2, David Silverwood via User <user at lists.gambas-basic.org> wrote:  
  
      Thank you very much Charlie and Gianluigi. Those were pointers in the right direction for me! I really appreciate your help. (Not to mention I just learned a lot from both of your code too.) 
  
       On Monday, April 29, 2019, 7:24:06 PM GMT+2, Charlie Ogier <charlie at cogier.com> wrote:  
  
     Hi David,
 
 Try this code: -
 
 Dim dDate As Date
 Dim sDate As New String[]
 
 edtDate.Text = "2019-04-29"         'I presume this is the format you get so you can take this line out. It was for me to test.
 
 If edtDate.Text Then
   sDate = Split(edtDate.Text, "-")
   dDate = Date(sDate[0], sDate[1], sDate[2])
   edtDate.Text = Format$(dDate, "dd/mm/yyyy")
 Endif
 
 If you use the ppa you can have the latest version of Gambas. Run the following command in Terminal and Gambas 3.13.0 will install. You will need a reasonable internet connection.
 
 sudo add-apt-repository -y ppa:gambas-team/gambas3 && sudo apt-get update && sudo apt-get -y install gambas3 
 
 Hope that helps,
 
 Charlie
 
 On 29/04/2019 14:40, David Silverwood via User wrote:
  
 
     Hi I'm new to the forum so please forgive any mistakes in protocol. I am also pretty new to Gambas and have a lot to learn, so please forgive once again any stupid questions or mistakes. Am trying to get Gambas dates to work for me. I have a SQLite3 database and as we know SQLite dates are stored as YYYY-MM-DD. It seems Gambas dates are stored MM-DD-YYYY which in South Africa doesn't work as our local dates are stored dd-mm-yyyy. Now, when I format$ my dateboxes/textboxes to read yyyy-mm-dd, depending on the date, I either get a blank box or the month and day are swopped and therefore also  renders the date unusable here.  My localisation settings for Linux Mint 18.3 KDE are correct. How can I convince Gambas to use the local date settings or at least format the date to the 'correct' format for our area? 
  The problem occurs when I load the dates from the database and try and format the dates to 'yyyy-mm-dd' using     If edtDate.Text Then     dDate = Val(edtDate.Text)     edtDate.Text = Format$(dDate, "yyyy-mm-dd")   Endif 
  Any but any suggestions/directions would be much appreciated. 
  Thanks 
  David   
  ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
 
   
 ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
        
 ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
     
  ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
 
 
----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
  
----[ 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/20190516/76e44744/attachment-0001.html>


More information about the User mailing list