isNumber vs isDate

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

isNumber vs isDate

Post by lohill » Mon Oct 08, 2012 7:01 pm

I can use isNumber to determine if an input field has had a number entered but I'm not sure how to tell if what was just entered is a legitimate date. There does not appear to be an isDate function that returns true or false like isNumber. I have tried converting the input to dateItems and looking at that result but even a plain number will cause dateitems to give a date. Do you have a suggestion for looking at the input on closeField to tell whether the input is really a date.

Thanks,
Larry

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

Re: isNumber vs isDate

Post by Klaus » Mon Oct 08, 2012 7:10 pm

Hi Larry,

you CAN in fact do this:
...
answer ("10/8/12" is a date)
## -> true
...
:D

Although there is no function "isDate".


Best

Klaus

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: isNumber vs isDate

Post by mwieder » Mon Oct 08, 2012 7:28 pm

Klaus-

The problem isn't with determining what is a date, but what isn't a date.

put 1234 is a date
==> true

the date functions are so flexible and forgiving of user inputs that it's harder for something to fail date verification.

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

Re: isNumber vs isDate

Post by Klaus » Mon Oct 08, 2012 9:06 pm

Hi Mark,

yes, you are right, always forget this :-/

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: isNumber vs isDate

Post by Mark » Mon Oct 08, 2012 9:42 pm

Hi,

I believe the isNumber and isDate are SuperCard syntax.

If a string is a number, then it is probably not date, but it could be seconds or milliseconds.

Code: Select all

put ("10/10/10" is not a number) and ("10/10/10" is a date)
--> true

put ("123456" is not a number) and ("123456" is a date)
--> false

put ("abcdefgh" is not a number) and ("abcdefgh" is a date)
--> false

The following is slightly problematic:
put ("10/10" is not a number) and ("10/10" is a date)
--> true
You might want to check that the date consists of 3 items in the last case.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: isNumber vs isDate

Post by dunbarx » Tue Oct 09, 2012 1:30 am

This goes way, way back. It can be managed easily, but talk about too flexible. You always have to remember to make sure that what you WANT to be a date is the only form that is allowed.

Craig

Post Reply