how do I check for invalid date?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
how do I check for invalid date?
G'day
I'm trying to allow the user of my stack to set a date using 3 scroll buttons to enter DD/MM/YY (in Australian format)
Trouble is, while I'm limiting the DD field to 1 thru 31, the user can enter an invalid date eg 31/6/2013. When I try to convert this to the long date, it doesn't correct it to 1/7/2013, but shows the american short date in the form of 6/31/2013.
Is there any way of checking and correcting date input?
Regards
OzSanta
I'm trying to allow the user of my stack to set a date using 3 scroll buttons to enter DD/MM/YY (in Australian format)
Trouble is, while I'm limiting the DD field to 1 thru 31, the user can enter an invalid date eg 31/6/2013. When I try to convert this to the long date, it doesn't correct it to 1/7/2013, but shows the american short date in the form of 6/31/2013.
Is there any way of checking and correcting date input?
Regards
OzSanta
Re: how do I check for invalid date?
Here I think this is silly but:
You will have to capture the date in the US format but you can present it any way. Most of the numbers up there would be variables.
But do you really want the date to roll into the next month?
Once again... There must be a better way
Simon
Code: Select all
on mouseUp
convert "6/1/2013" to dateItems --MMDDYYYY
put it into tDate
add 31 to item 3 of tDate
convert tDate to dateItems
subtract 1 from item 3 of tDate
end mouseUp
But do you really want the date to roll into the next month?
Once again... There must be a better way
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: how do I check for invalid date?
Ok answering my own statement:
This will convert to 2013,7,1,0,0,0,2
Just the year,month,day, with 4 0's
Simon
Code: Select all
on mouseUp
convert "2013,6,31,0,0,0,0" to dateItems
put it into tDate
end mouseUp
Just the year,month,day, with 4 0's
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: how do I check for invalid date?
G'day, & thanks
I just worked out a better way.
Regards
OzSanta
I just worked out a better way.
Regards
OzSanta
Code: Select all
on setStartTime
put field"Start Date Month"&"/"&field "Start Date Day"&"/"&field "Start Date Year" into checkDate
convert checkDate to dateitems
repeat
if item 3 of checkdate = "" then
put field "Start Date Day" -1 into field "Start Date Day"
put field"Start Date Month"&"/"&field "Start Date Day"&"/"&field "Start Date Year" into checkDate
convert checkDate to dateitems
else
exit repeat
end if
end repeat
convert checkDate to long system date
put checkDate into field "Start Date"
end setStartTime
Re: how do I check for invalid date?
If you did:
You wouldn't need the if/thens
Simon
Code: Select all
on setStartTime
put field"Start Date Month"&"comma"&field "Start Date Day"&"comma"&field "Start Date Year" &"0,0,0,0" into checkDate
convert checkDate to dateitems
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: how do I check for invalid date?
G'day Simon, and thank you.
At first I thought it would be necessary to convert 31/6/2013 to 1/7/2013, but my routine leaves the month alone, and reverses the 31 to 30 , or even 34 back to 30.
I've also worked out a way to convert the long date day if it's out of range, without altering the month.
At first I thought it would be necessary to convert 31/6/2013 to 1/7/2013, but my routine leaves the month alone, and reverses the 31 to 30 , or even 34 back to 30.
I've also worked out a way to convert the long date day if it's out of range, without altering the month.
Code: Select all
on checkTheDate thefield
put field id thefield of this card into tempdate
convert tempdate to dateitems
repeat
if item 3 of tempdate > 2000 then
put word 2 of item 2 of tempdate into temp2
put temp2 -1 into temp3
put replaceText (tempdate,temp2,temp3) into tempdate
convert tempdate to dateitems
else
exit repeat
end if
end repeat
convert tempdate to long date
put tempdate into field id thefield of this card
end checkTheDate
Re: how do I check for invalid date?
I've realized my code was restricted to long dates, and long system dates did not work, so I've modified it. This will reduce any number of extraneous days for any month.
I'm finding LiveCode to be great fun to program, after only a few days.
The handler is called like so...
on returninField
checkTheDate id of me
end returninField
Regards
OzSanta
I'm finding LiveCode to be great fun to program, after only a few days.
The handler is called like so...
on returninField
checkTheDate id of me
end returninField
Regards
OzSanta
Code: Select all
on checkTheDate thefield
put field id thefield of this card into tempdate
convert tempdate to dateitems
put "long date" into keepTypeFlag
if number of items of tempdate = 2 then
put item 1 of tempdate &", "& word 2 of item 2 of tempdate&" "& word 1 of item 2 of tempdate&", "&word 3 of item 2 of tempdate into theStoredSystemDate
convert theStoredSystemDate to dateitems
put theStoredSystemDate into tempdate
put "long system date" into keepTypeFlag
end if
repeat
if item 3 of tempdate > 2000 then
put item 2 of tempdate into tempTIME
put word 2 of tempTIME into temp2
put temp2 -1 into temp3
put item 1 of tempdate & ", " & word 1 of item 2 of tempdate&" "&temp3&","&item 3 of tempdate into testdate
convert testdate to dateitems
put testdate into tempdate
else
exit repeat
end if
end repeat
if keepTypeFlag = "long date" then
convert tempdate to long date
else
convert tempdate to long system date
end if
put tempdate into field id thefield of this card
end checkTheDate