Path: csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.php Subject: Re: Check for military time Date: Thu, 22 Oct 2015 11:12:52 +0200 Organization: PointedEars Software (PES) Lines: 33 Message-ID: <2052274.t68nZ4G7dp@PointedEars.de> References: <%kSVx.210845$HZ6.47102@fx12.iad> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1445505177 9133 eJwFwQkBwDAIA0BLUCBp5fAM/xJ2FwZF0xHw2NgeirfjaZfNtweiUyjzfkfm3o005DKYJP0HImYRCA== (22 Oct 2015 09:12:57 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Thu, 22 Oct 2015 09:12:57 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwNx9EBRDEEBMCWOKwoh8j2X8K7+ZswKG46Ah4MJmRuOVLk7SzZUT92K0ppw+en6x39z6P3UZCzx7TN7jY+a0oWVw== Cancel-Lock: sha1:l4LLHMzr59mrwZDlyRNT7Qmz2mQ= X-NNTP-Posting-Host: eJwFwYkBwCAIA8CVCE/UcYQ2+4/gXQXBWclilkr/16YxWYcKvRvhBxpuDtBzz0XDkWmjVf4ALygRPg== Xref: csiph.com comp.lang.php:15728 Lew Pitcher wrote: > […] "Richard Yates" […] wrote: >> On 20 Oct 2015 19:00:19 GMT, Derek Turner wrote: >>> On Tue, 20 Oct 2015 18:57:34 +0000, Derek Turner wrote: >>>> Is there a quick and dirty way to check that >>>> >>>> substr($string, 0 ,3) is a valid military time, ie. 0000-2359? >>> sorry, that should, of course, read ($string, 0, 4) >> >> This seems to work, but I did not test all cases: >> >> echo (strtotime($time)) ? 'Pass' : 'Fail'; > > PHP Version 5.4.45 > > I tried all integer test cases between 0000 and 2599, and found that this > test seems to fail on the range "1960" to "1999". On the off chance that > the strtotime() call interpreted its argument as a date, […] Both of you are overthinking the problem. Compared to this, a solution based on string comparison (left as an exercise for the reader) is a one-or- two-liner (after all, the request said “quick and dirty”). For another approach, consider , which can serve as a substitute on Windows where, according to the PHP manual, is unavailable. -- PointedEars Zend Certified PHP Engineer Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.