Modify date

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
AlessioForconi
Posts: 90
Joined: Sun Feb 15, 2015 2:51 pm

Modify date

Post by AlessioForconi » Wed May 08, 2019 6:36 am

Hello

I'm back to you with a question of mine, simple for everyone but hard for me :D

I have this data which I retrieve from a database

Code: Select all

put revDataFromQuery(, , conn, sqlGodute) into myArray
which contains this

21 2018-12-23 7 Ferie
22 2018-12-22 8 ROL
24 2019-03-27 1 ROL
30 2019-04-29 4 Banca Ore

my goal is to extract all the dates to modify them before showing them in a datagrid.
To do this, go write this

Code: Select all

 set the itemDel to tab
 repeat with x = 1 to the number of lines of myArray
      answer item 2 of line x of myArray
      put item 2 of line x of myArray into miadata
      convert miadata to short date
      answer miadata
 end repeat
the problem is that miadata does not change, it remains the same even after convert.
No convert format works

What the hell am I wrong?

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Modify date

Post by bogs » Wed May 08, 2019 7:48 am

Hi Alessio,

Maybe this lesson will help you understand the conversion a bit better.

The date and the short date are identical, by the way.
Dictionary wrote: The date form returns the month number, the day of the month, and the last two digits of the year, separated by slashes (/).

The short date form returns the same value as the date form.
If you need those 3 digits in a specific order, you could set the itemDelimiter to "-" and arrange the items however you need it.
Image

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Modify date

Post by Klaus » Wed May 08, 2019 9:33 am

Buongiorno Alessio,

and do not confuse yourself:
put revDataFromQuery(, , conn, sqlGodute) into myArray
revdatafromquery() does NOT return an ARRAY, but a CR and TAB delimited simple list of text!
:D


Best

Klaus

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: Modify date

Post by richmond62 » Wed May 08, 2019 10:32 am

Iff you want to convert your dates to this format: Day-Month-Year I suppose you could do this:

Code: Select all

set the itemDel to tab
 repeat with x = 1 to the number of lines of myArray
      answer item 2 of line x of myArray
      put item 2 of line x of myArray into miadata
      set the itemDel to "-"
      put item 1 of miadata into ANNUS
      put item 2 of miadata into MENSIS
      put item 3 of miadata into DIES
      put DIES & "-" & MENSUS & "-" & ANNUS into miadata
      answer miadata
      set the itemDel to tab
 end repeat
NOT rocket science, just a thought over a cup of coffee at lunchtime. 8)

AlessioForconi
Posts: 90
Joined: Sun Feb 15, 2015 2:51 pm

Re: Modify date

Post by AlessioForconi » Thu May 09, 2019 7:02 am

Klaus wrote:
Wed May 08, 2019 9:33 am
Buongiorno Alessio,

and do not confuse yourself:
put revDataFromQuery(, , conn, sqlGodute) into myArray
revdatafromquery() does NOT return an ARRAY, but a CR and TAB delimited simple list of text!
:D


Best

Klaus
Yes Klaus. I took an example on how to extract the data from the database with the query, myArray was written and I, with guilty laziness, didn't verify that it was really an array. Until today. :oops:

AlessioForconi
Posts: 90
Joined: Sun Feb 15, 2015 2:51 pm

Re: Modify date

Post by AlessioForconi » Thu May 09, 2019 7:03 am

bogs wrote:
Wed May 08, 2019 7:48 am
Hi Alessio,

Maybe this lesson will help you understand the conversion a bit better.

The date and the short date are identical, by the way.
Dictionary wrote: The date form returns the month number, the day of the month, and the last two digits of the year, separated by slashes (/).

The short date form returns the same value as the date form.
If you need those 3 digits in a specific order, you could set the itemDelimiter to "-" and arrange the items however you need it.
Thank you. It's really useful.

AlessioForconi
Posts: 90
Joined: Sun Feb 15, 2015 2:51 pm

Re: Modify date

Post by AlessioForconi » Thu May 09, 2019 7:05 am

richmond62 wrote:
Wed May 08, 2019 10:32 am
Iff you want to convert your dates to this format: Day-Month-Year I suppose you could do this:

Code: Select all

set the itemDel to tab
 repeat with x = 1 to the number of lines of myArray
      answer item 2 of line x of myArray
      put item 2 of line x of myArray into miadata
      set the itemDel to "-"
      put item 1 of miadata into ANNUS
      put item 2 of miadata into MENSIS
      put item 3 of miadata into DIES
      put DIES & "-" & MENSUS & "-" & ANNUS into miadata
      answer miadata
      set the itemDel to tab
 end repeat
Yes. I arrived at the same concusion following the bogs suggestion.
richmond62 wrote:
Wed May 08, 2019 10:32 am
NOT rocket science, just a thought over a cup of coffee at lunchtime. 8)
Never underestimate the power of a cup of coffee :D

Post Reply