Jump to content
php.lv forumi

Regexp riekš yyyyMMddHHmmss


Sasa

Recommended Posts

man datums un laik vajadzīgs formā yyyyMMddHHmmss kā lai ievadīto stringu pārbauda vai tas atbilst datumam un laikam

šobrīd mana regulārā izteiksme, kas savākta no diviem atsevišķiem diez ko labi nestrādā pārbaudot laika daļu:

(19|20)\d\d()(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])(([0-1]?[0-9])|([2][0-3]))([0-5]?[0-9])(([0-5]?[0-9]))

testēju uz apmēram kaut kā ša: 20100928100000

Link to comment
Share on other sites

function check_date($datestr){
$m = array();
if(!preg_match('/^(?P<year>\d{4})(?P<month>\d{2})(?P<day>\d{2})(?P<hour>\d{2})(?P<minute>\d{2})(?P<second>\d{2})$/', $datestr, $m)) return false;
if(($t = mktime((int)$m['hour'], (int)$m['minute'], (int)$m['second'], (int)$m['month'], (int)$m['day'], (int)$m['year'])) === false) return false;
return $datestr == date('YmdHis', $t);
}
var_dump(check_date('20100928100000'), check_date('1234'), check_date('20131928105699'));

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...