[Newbies] How to test a String if it is a valid date?

Ron Teitelbaum ron at usmedrec.com
Wed Mar 30 02:05:08 UTC 2016


Hi Joe,

You could just handle the error.

['1/22/2016' asDate class = Date ] on: Error do: [:ex | ^false] 
returns true

['15/22/2016' asDate class = Date ] on: Error do: [:ex | ^false] 
returns false

Or even 

[myDate := '1/22/2016' asDate] on: Error do: [:ex | ^nil].

Then you can just check if myDate isNil.

All the best,

Ron Teitelbaum
Head Of Engineering
3D Immersive Collaboration Consulting
ron at 3Dicc.com
Follow Me On Twitter: @RonTeitelbaum
www.3Dicc.com 
https://www.google.com/+3Dicc

> -----Original Message-----
> From: beginners-bounces at lists.squeakfoundation.org [mailto:beginners-
> bounces at lists.squeakfoundation.org] On Behalf Of Joseph Alotta
> Sent: Tuesday, March 29, 2016 8:07 PM
> To: beginners at lists.squeakfoundation.org
> Subject: [Newbies] How to test a String if it is a valid date?
> 
> Greetings,
> 
> I want to test a String to see if it can be a Date using mm/dd/yyyy format.  I
> want something that won’t cause a walkback window.  Is there a String
> method isValidAsADate?
> 
> Sincerely,
> 
> Joe.
> 
> 
> 
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners



More information about the Beginners mailing list