Get date from user

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

CAsba
Posts: 431
Joined: Fri Sep 30, 2022 12:11 pm

Re: Get date from user

Post by CAsba » Wed Nov 09, 2022 11:52 am

Hi all,
Trying to get the long date from user-entered year/month/day, it does not convert to long date.
My code is
on mouseup
set the itemDelimiter to "/"
put field "startyr" & "/" into field "fieldannounce2"
set the itemDelimiter to "/"
put field "startmth" & "/" after field "fieldannounce2"
set the itemDelimiter to "/"
put field "startday" after field "fieldannounce2"
set the itemDelimiter to "/"
put fld "fieldannounce2" into tDate
set the itemDelimiter to "/"
convert tDate to DATEITEMS
set the itemDelimiter to "/"
convert tDate to date
answer tDate
convert tdate to long date
answer tDate
put tdate into field "formatted date"
convert field "formatted date" to long date
end mouseup
Neither answer gives the long date, nor does 'formatted date'.
Any ideas, please ?

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

Re: Get date from user

Post by Klaus » Wed Nov 09, 2022 12:25 pm

I mean CODE tags, not QUOTE tags, sounds similar however... 8)

OK, here a working script (in CODE tags) with comments.
Your main problem was to supply a wrong date format to your commands!

Code: Select all

on mouseup
   
   ## ITEMDELIMITER will last for the complete handler, so you only need to set it ONCE!
   ## However it is not used in this handler so you can leave it out here completely!
   ## set the itemDelimiter to "/"
   
   ## Wrong ORDER for (english) date!!!
   ## yyyy/mm/dd does not work in LC!
   #   put field "startyr" & "/" into field "fieldannounce2"
   #   put field "startmth" & "/" after field "fieldannounce2"
   #   put field "startday" after field "fieldannounce2"
   
   ## the date in LC -> mm/dd/yy      
   put field "startmth" & "/" into field "fieldannounce2"
   put field "startday"& "/" after field "fieldannounce2"
   put field "startyr" after field "fieldannounce2"
   put fld "fieldannounce2" into tDate
   
   ## You have to tell LC that is is a date now!
   ## However no need to to do this extra conversion!
   ## convert tDate from date to DATEITEMS
   ## convert tDate to date
   ## answer tDate
   
   ## See above, LC needs to know what to do:
   convert tDate from date to long date 
   put tDate into field "formatted date"
   
   ## Not neccessary, since you do not do anything with the converted date
   ## convert field "formatted date" to long date 
end mouseup

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

Re: Get date from user

Post by Klaus » Wed Nov 09, 2022 12:35 pm

In short:

Code: Select all

on mouseup
   put field "startmth" & "/" into field "fieldannounce2"
   put field "startday"& "/" after field "fieldannounce2"
   put field "startyr" after field "fieldannounce2"
   put fld "fieldannounce2" into tDate
   convert tDate from date to long date 
   put tDate into field "formatted date"
end mouseup

CAsba
Posts: 431
Joined: Fri Sep 30, 2022 12:11 pm

Re: Get date from user

Post by CAsba » Wed Nov 09, 2022 12:36 pm

Klaus, you're a STAR !
Many thanks.

Post Reply