Date manipulation oddity

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
nicoloose
Posts: 99
Joined: Mon Sep 16, 2013 3:35 pm

Date manipulation oddity

Post by nicoloose » Wed Oct 23, 2013 10:00 am

I have two date fields and I want to convert them to a format of "YYYY-MM-DD" and am successful in converting the first date but when the code comes to convert the second date, it gives a very weird result.

put empty into tStart
put empty into fDate
put field "startDate" into fDate
convert fDate to dateitems
put (the item 1 of fDate) & "-" & (the item 2 of fDate) & "-" & (the item 3 of fDate) into tStart

set the itemDelimiter to "-"
put format("%02s", item 2 of tStart) into item 2 of tStart
put format("%02s", item 3 of tStart) into item 3 of tStart

****** RESULT = 2013-01-01 *******

put empty into tEnd
put field "endDate" into eDate
convert eDate to dateitems
put (the item 1 of eDate) & "-" & (the item 2 of eDate) & "-" & (the item 3 of eDate) into tEnd

set the itemDelimiter to "-"
put format("%02s", item 2 of tEnd) into item 2 of tEnd
put format("%02s", item 3 of tEnd) into item 3 of tEnd

******** RESULT = 2013,1,31,0,0,0,5-00-00 ********

If I swap the two pieces of code around, the same things happens. Always the second date that has this issue?

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Date manipulation oddity

Post by bangkok » Wed Oct 23, 2013 11:48 am

Ouh la la... don't bother... keep it simple ! :)

From Date&Time library of Sarah.

http://www.troz.net/rev/stacks/DateTime.rev

Code: Select all

function englishToSQLdate pDate
   if pDate is empty then put the short english date into pDate
   convert pDate from short english date to dateItems
   put item 2 of pDate into m
   if m < 10 then put "0" before m
   put item 3 of pDate into d
   if d < 10 then put "0" before d
   return item 1 of pDate & "-" & m & "-" & d
end englishToSQLdate()
on mouseup
answer englishToSQLdate ()
end mouseup

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Date manipulation oddity

Post by bn » Wed Oct 23, 2013 12:03 pm

Hi Nicoloose,

your second date does not work because you forgot to set the itemDelimiter to "," after the first conversion and before the second conversion.

It should work if you put

Code: Select all

set the itemDelimiter to ","
before

Code: Select all

put empty into tEnd
Kind regards
Bernd

nicoloose
Posts: 99
Joined: Mon Sep 16, 2013 3:35 pm

Re: Date manipulation oddity

Post by nicoloose » Thu Oct 24, 2013 11:02 am

Simplicity and logic are not among the lines of the things in me!
Thanks for the help!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Date manipulation oddity

Post by jacque » Thu Oct 24, 2013 5:30 pm

Simplicity and logic are not among the lines of the things in me!
LOL! But you learn fast. :)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply